12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- namespace KYFramework;
- [ObjectSystem]
- public class TimerAwakeSystem: AwakeSystem<Timer>
- {
- public override void Awake(Timer self)
- {
- self.dt1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- self.dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
- self.FrameTime = self.ClientNow();
- }
- }
- [ObjectSystem]
- public class TimerUpdateSystem : UpdateSystem<Timer>
- {
- public override void Update(Timer self)
- {
- self.FrameTime = self.ClientNow();
- }
- }
- public static class TimerSystem
- {
- /// <summary>
- /// 根据时间戳获取时间
- /// </summary>
- public static DateTime ToDateTime(this Timer self,long timeStamp)
- {
- return self.dt.AddTicks(timeStamp * 10000);
- }
-
- // 线程安全
- public static long ClientNow(this Timer self)
- {
- return (DateTime.UtcNow.Ticks - self.dt1970.Ticks) / 10000;
- }
-
- public static long ServerNow(this Timer self)
- {
- return self.ClientNow() + self.ServerMinusClientTime;
- }
-
- public static long ClientFrameTime(this Timer self)
- {
- return self.FrameTime;
- }
-
- public static long ServerFrameTime(this Timer self)
- {
- return self.FrameTime + self.ServerMinusClientTime;
- }
-
- public static long Transition(this Timer self,DateTime d)
- {
- return (d.Ticks - self.dt.Ticks) / 10000;
- }
- }
|