Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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));
 }
Esempio n. 5
0
 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));
 }