123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- namespace KYFramework;
- public enum TimerClass
- {
- None,
- OnceTimer,
- OnceWaitTimer,
- RepeatedTimer,
- }
- public class TimerAction
- {
- public static TimerAction Create(long id, TimerClass timerClass, long startTime, long time, int type, object obj)
- {
- TimerAction timerAction = Game.ObjectPool.Fetch<TimerAction>();
- timerAction.Id = id;
- timerAction.TimerClass = timerClass;
- timerAction.StartTime = startTime;
- timerAction.Object = obj;
- timerAction.Time = time;
- timerAction.Type = type;
- return timerAction;
- }
- public long Id;
-
- public TimerClass TimerClass;
- public object Object;
- public long StartTime;
- public long Time;
- public int Type;
-
- public void Recycle()
- {
- this.Id = 0;
- this.Object = null;
- this.StartTime = 0;
- this.Time = 0;
- this.TimerClass = TimerClass.None;
- this.Type = 0;
- Game.ObjectPool.Recycle(this);
- }
- }
- public struct TimerCallback
- {
- public object Args;
- }
- public class TimerComponent : Component
- {
- public static TimerComponent Instance;
- /// <summary>
- /// key: time, value: timer id
- /// </summary>
- public readonly MultiMap<long, long> TimeId = new();
- public readonly Queue<long> timeOutTime = new();
- public readonly Queue<long> timeOutTimerIds = new();
- public readonly Dictionary<long, TimerAction> timerActions = new();
- public long idGenerator;
- // 记录最小时间,不用每次都去MultiMap取第一个值
- public long minTime = long.MaxValue;
- }
|