提交功能
This commit is contained in:
88
Core/Time.cs
Normal file
88
Core/Time.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
namespace ACBuildService;
|
||||
|
||||
public static class Time
|
||||
{
|
||||
public const long OneDay = 86400000;
|
||||
public const long Hour = 3600000;
|
||||
public const long Minute = 60000;
|
||||
|
||||
private static TimeInfo _timeInfo = new TimeInfo();
|
||||
|
||||
public static long Now => _timeInfo.Now();
|
||||
|
||||
public static long NowSeconds => Now / 1000;
|
||||
|
||||
public static DateTime DateTimeNow => DateTime.Now;
|
||||
|
||||
public static long FrameTime => _timeInfo.FrameTime;
|
||||
|
||||
public static event Action OnUpdate;
|
||||
public static event Action OnLateUpdate;
|
||||
|
||||
internal static void Awake()
|
||||
{
|
||||
}
|
||||
|
||||
internal static void Update()
|
||||
{
|
||||
_timeInfo.Update();
|
||||
OnUpdate?.Invoke();
|
||||
}
|
||||
|
||||
internal static void LateUpdate()
|
||||
{
|
||||
OnLateUpdate?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
public class TimeInfo
|
||||
{
|
||||
private int timeZone;
|
||||
|
||||
public int TimeZone
|
||||
{
|
||||
get => timeZone;
|
||||
set
|
||||
{
|
||||
timeZone = value;
|
||||
dt = dt1970.AddHours(TimeZone);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly DateTime dt1970;
|
||||
private DateTime dt;
|
||||
|
||||
public long FrameTime;
|
||||
|
||||
public TimeInfo()
|
||||
{
|
||||
dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
FrameTime = Now();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
FrameTime = Now();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据时间戳获取时间
|
||||
/// </summary>
|
||||
public DateTime ToDateTime(long timeStamp)
|
||||
{
|
||||
return dt.AddTicks(timeStamp * 10000);
|
||||
}
|
||||
|
||||
// 线程安全
|
||||
public long Now()
|
||||
{
|
||||
return (DateTime.UtcNow.Ticks - dt1970.Ticks) / 10000;
|
||||
}
|
||||
|
||||
|
||||
public long Transition(DateTime d)
|
||||
{
|
||||
return (d.Ticks - dt.Ticks) / 10000;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user