void FixedUpdate() { //delete first if (mToDelPhysicTimerSet.Count > 0) { mPhysicTimerSet.RemoveWhere(MatchForFixedUpdate); mToDelPhysicTimerSet.Clear(); } if (mPhysicTimerSet.Count > 0) { mPhysicTimersToInvoke.AddRange(mPhysicTimerSet); LogDC.LogEx("physic timer count ", mPhysicTimersToInvoke.Count); foreach (var timer in mPhysicTimersToInvoke) { timer.Update(); } mPhysicTimersToInvoke.Clear(); } //avoid执行中添加新action mNextFixedUpdateToInvokes.AddRange(mNextFixedUpdate); mNextFixedUpdate.Clear(); foreach (var action in mNextFixedUpdateToInvokes) { if (action != null) { action(); } } mNextFixedUpdateToInvokes.Clear(); }
public static void RemoveNormal(DCBaseTimer timer) { if (null == Instance) { return; } LogDC.Log("add to remove"); Instance.mToDelTimerSet.Add(timer); }
public void Destroy() { LogDC.Log("Destroy 1"); if (mDestroyed) { return; } mDestroyed = true; LogDC.Log("Destroy 2"); if (mPhysic) { DCTimer.RemovePhysic(this); } else { DCTimer.RemoveNormal(this); } }
void Update() { //update 类型的timer //delete first if (mToDelTimerSet.Count > 0) { mTimerSet.RemoveWhere(MatchForUpdate); mToDelTimerSet.Clear(); } if (mTimerSet.Count > 0) { mTimersToInvoke.AddRange(mTimerSet); LogDC.LogEx("timer count ", mTimersToInvoke.Count); foreach (var timer in mTimersToInvoke) { timer.Update(); } mTimersToInvoke.Clear(); } //延时执行部分 foreach (var actionRecord in mActionRecords) { actionRecord.Update(); if (actionRecord.IsComplete()) { mActionRecordsToDel.Add(actionRecord); } } //防止action update的时候有往集合里面增加的操作 if (mActionRecordsToDel.Count > 0) { mActionRecords.RemoveWhere(MatchDelRecord); foreach (var record in mActionRecordsToDel) { record.Notify(); } mActionRecordsToDel.Clear(); } }