private void Init(float sec, OnTimeUpVoid funcVoid, OnTimeUp func, object obj, IDroppableItem timerDropper, bool onceCall, bool realtimeTimer, int engineLoop) { if (funcVoid != null) { onTimeUpVoidEvent = funcVoid; } if (func != null) { onTimeUpEvent = func; } _once = onceCall; _realtime = realtimeTimer; _firedObj = obj; _engineLoop = engineLoop; if (Mathf.Approximately(sec, 0)) { Call(); if (_once) { onTimeUpEvent = null; onTimeUpVoidEvent = null; return; } } _timeStep = sec; _work = true; if (timerDropper != null) { _dropper = timerDropper; _dropper.onDrop += InternalDrop; } Sync.Add(() => _timers[_engineLoop].Add(this), _engineLoop); }
public override void Drop() { if (dropped) { return; } if (_dropper != null) { _dropper.onDrop -= InternalDrop; } _dropper = null; Pause(); onTimeUpEvent = null; onTimeUpVoidEvent = null; Sync.Add(() => _timers[_engineLoop].Remove(this), _engineLoop); base.Drop(); }
private Timer(float sec, OnTimeUpVoid func, IDroppableItem dropper, bool once = false, bool realtime = false, int?engineLoop = null) { Init(sec, func, null, null, dropper, once, realtime, engineLoop ?? Loops.TIMER); }
public static Timer CreateRealtime(float sec, OnTimeUpVoid func, IDroppableItem dropper, bool once = false, int?engineLoop = null) { return(new Timer(sec, func, dropper, once, true, engineLoop)); }
public static Timer Create(float sec, OnTimeUpVoid func, IDroppableItem dropper, bool once = false, int engineLoop = -1) { return(new Timer(sec, func, dropper, once, false, engineLoop)); }