Files
2026-03-04 10:03:45 +08:00

129 lines
3.9 KiB
C#

using System;
using UnityEngine;
namespace Artngame.SKYMASTER
{
public class TimerSKYMASTER : MonoBehaviour
{
private SkyMasterManager skyManager;
public bool realWorldTime;
public bool staticReference;
public bool startWithRealTime;
public int startYear = 2016;
public int startMonth = 6;
public int startDay = 6;
public int startHour = 12;
public int currentYear = 2016;
public int currentMonth = 6;
public int currentDay = 6;
private float shiftTime;
public bool enableGUI;
private float previousTime;
private DateTime startGameTime;
private DateTime startRealTime;
private DateTime currentGameTime;
private DateTime currentRealTime;
private bool startedWithRealTime;
[Tooltip("Game hours that correspond to one real world hour")]
public float timeScaling = 10f;
private void Start()
{
skyManager = GetComponent<SkyMasterManager>();
float num = DateTime.Now.Hour * 3600;
float num2 = DateTime.Now.Minute * 60;
float num3 = DateTime.Now.Second;
float num4 = DateTime.Now.Millisecond;
float num5 = num + num2 + num3 + num4 / 1000f;
shiftTime = num5;
skyManager.Current_Time = startHour;
previousTime = skyManager.Current_Time;
startGameTime = new DateTime(startYear, startMonth, startDay, startHour, 0, 0);
startRealTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
}
private void Update()
{
if (!startedWithRealTime && startWithRealTime)
{
startGameTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
startedWithRealTime = true;
}
float num = DateTime.Now.Hour * 3600;
float num2 = DateTime.Now.Minute * 60;
float num3 = DateTime.Now.Second;
float num4 = DateTime.Now.Millisecond;
float num5 = num + num2 + num3 + num4 / 1000f;
if (realWorldTime)
{
skyManager.Auto_Cycle_Sky = true;
skyManager.SPEED = 0.0001f * timeScaling;
float num6 = num5 / (3600f / timeScaling);
skyManager.Current_Time = num6 % 24f;
currentGameTime = DateTime.Now;
}
else
{
skyManager.Auto_Cycle_Sky = true;
skyManager.SPEED = 0.0001f * timeScaling;
if (!staticReference)
{
float num7 = (num5 - shiftTime) / (3600f / timeScaling);
skyManager.Current_Time = (skyManager.Current_Time + num7) % 24f;
shiftTime = num5;
}
else
{
currentRealTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
float num8 = (float)(currentRealTime - startRealTime).TotalSeconds;
currentGameTime = startGameTime;
currentGameTime = currentGameTime.AddSeconds(num8);
float num9 = currentGameTime.Hour * 3600;
float num10 = currentGameTime.Minute * 60;
float num11 = currentGameTime.Second;
float num12 = currentGameTime.Millisecond;
float num13 = (num9 + num10 + num11 + num12 / 1000f) / (3600f / timeScaling);
skyManager.Current_Time = num13 % 24f;
}
}
if (skyManager.Current_Time < previousTime)
{
currentDay++;
}
currentMonth = currentDay / 30 % 12;
currentYear = currentDay / 30 / 12;
previousTime = skyManager.Current_Time;
}
private void OnGUI()
{
if (enableGUI)
{
GUI.TextField(new Rect(500f, 400f, 400f, 22f), "Game Date =" + currentGameTime.ToLongDateString());
GUI.TextField(new Rect(500f, 422f, 400f, 22f), "Game Time =" + currentGameTime.ToLongTimeString());
GUI.TextField(new Rect(500f, 444f, 400f, 22f), "Sky Master Day Time =" + skyManager.Current_Time);
GUI.TextField(new Rect(500f, 466f, 400f, 22f), "Sky Master Day = " + (1 + currentDay % 30) + ", Month: " + (currentMonth + 1) + ", Year:" + (currentYear + 1));
}
}
}
}