public void Awake() { this.timerActions = new ITimer[TimeTypeMax]; HashSet <Type> types = Game.EventSystem.GetTypes(typeof(TimerAttribute)); foreach (Type type in types) { ITimer iTimer = Activator.CreateInstance(type) as ITimer; if (iTimer == null) { Log.Error($"Timer Action {type.Name} 需要继承 ITimer"); continue; } object[] attrs = type.GetCustomAttributes(typeof(TimerAttribute), false); if (attrs.Length == 0) { continue; } foreach (object attr in attrs) { TimerAttribute timerAttribute = attr as TimerAttribute; this.timerActions[timerAttribute.Type] = iTimer; } } }
private static void Init(this TimerComponent self) { self.foreachFunc = (k, v) => { if (k > self.timeNow) { self.minTime = k; return(false); } self.timeOutTime.Enqueue(k); return(true); }; self.timerActions = new ITimer[TimerComponent.TimeTypeMax]; List <Type> types = Game.EventSystem.GetTypes(typeof(TimerAttribute)); foreach (Type type in types) { ITimer iTimer = Activator.CreateInstance(type) as ITimer; if (iTimer == null) { Log.Error($"Timer Action {type.Name} 需要继承 ITimer"); continue; } object[] attrs = type.GetCustomAttributes(typeof(TimerAttribute), false); if (attrs.Length == 0) { continue; } foreach (object attr in attrs) { TimerAttribute timerAttribute = attr as TimerAttribute; self.timerActions[timerAttribute.Type] = iTimer; } } }