Beispiel #1
0
 public void Cleanup()
 {
     if (action != null)
     {
         action.Dispose();
         action = null;
     }
 }
Beispiel #2
0
        public ulong Add(int delay, bool once, TimeHandleCallback fn)
        {
            var id    = ++_idgen;
            var timer = GetTimeHandle(id, delay, once, fn);

            _timeHandles[id] = timer;
            Rearrange(timer);
            // UnityEngine.Debug.Log($"[Scheduler] Add timer#{timer.id} deadline: {timer.deadline}");
            return(id);
        }
Beispiel #3
0
        private TimeHandle GetTimeHandle(ulong id, int delay, bool once, TimeHandleCallback fn)
        {
            var        available = _pool.Count;
            TimeHandle timer;

            if (available > 0)
            {
                timer = _pool[available - 1];
                _pool.RemoveAt(available - 1);
            }
            else
            {
                timer = new TimeHandle();
            }
            timer.id       = id;
            timer.delay    = delay < 0 ? 0 : delay;
            timer.deadline = timer.delay + _elapsed;
            timer.action   = fn;
            timer.once     = once;
            timer.deleted  = false;
            timer.slot     = null;
            return(timer);
        }