/// <summary> /// Sets the timer. /// </summary> /// <param name='observer'> /// The TimerObserverOrSubject you need to listen /// </param> /// <param name='callback'> /// The callback when time is up. /// </param> /// <param name='arg'> /// Argument of the callback. /// </param> /// <param name='timepass'> /// Timepass before calling the callback. /// </param> public void SetTimer(TimerObserverOrSubject observer, OnCallBack callback, object arg, float timepass) { if (observer != null && callback != null) { Timer timer = new Timer(observer, callback, arg, timepass); m_Timers.Add(timer); } }
public Timer(TimerObserverOrSubject observer, OnCallBack callback, object arg, float time) { m_Observer = observer; m_Callback = callback; m_Arg = arg; m_Subject = null; m_IsCanDoFunc = null; m_ArgForIsCanDoFunc = null; m_PassTime = time; }
public Timer(TimerObserverOrSubject observer, OnCallBack callback, object arg, TimerObserverOrSubject subject, OnIsCanDo isCanDoFunc, object argForIsCanDo) { m_Observer = observer; m_Callback = callback; m_Arg = arg; m_Subject = subject; m_IsCanDoFunc = isCanDoFunc; m_ArgForIsCanDoFunc = argForIsCanDo; m_PassTime = 0; }
/// <summary> /// Clears all Timers of the observer. /// </summary> /// <param name='observer'> /// The TimerObserverOrSubject you need to clear /// </param> public void ClearTimer(TimerObserverOrSubject observer) { List <Timer> needRemovedTimers = new List <Timer>(); foreach (Timer timer in m_Timers) { if (timer.m_Observer == observer || timer.m_Subject) { needRemovedTimers.Add(timer); } } foreach (Timer timer in needRemovedTimers) { m_Timers.Remove(timer); } }
/// <summary> /// Sets the timer. /// </summary> /// <param name='observer'> /// The TimerObserverOrSubject you need to listen /// </param> /// <param name='callback'> /// The callback when condition is true. /// </param> /// <param name='arg'> /// Argument of the callback. /// </param> /// <param name='observer'> /// The TimerObserverOrSubject you need to observe /// </param> /// <param name='isCanDoFunc'> /// The condition function, must return a boolean. /// </param> /// <param name='argForIsCanDo'> /// Argument for condition function. /// </param> public void SetTimer(TimerObserverOrSubject observer, OnCallBack callback, object arg, TimerObserverOrSubject subject, OnIsCanDo isCanDoFunc, object argForIsCanDo) { if (observer == null || subject == null || callback == null || isCanDoFunc == null) { return; } if (isCanDoFunc(argForIsCanDo)) { callback(arg); return; } Timer timer = new Timer(observer, callback, arg, subject, isCanDoFunc, argForIsCanDo); m_Timers.Add(timer); }