Пример #1
0
        public void RegisterTimer(float interval, int repeat, bool startImmediately, TimerEntry.TimerHandler timerCallback,
                                  TimerEntry.CompleteHandler completeCallback, object param = null)
        {
            TimerEntry timer = new TimerEntry(interval, repeat, startImmediately, timerCallback, completeCallback, param);

            this._timers.Add(timer);
        }
Пример #2
0
        public void UnregisterTimer(TimerEntry.TimerHandler callback)
        {
            int count = this._timers.Count;

            for (int i = 0; i < count; i++)
            {
                TimerEntry timerEntry = this._timers[i];
                if (timerEntry.timerCallback == callback)
                {
                    this._timersToRemove.Add(timerEntry);
                }
            }
        }
Пример #3
0
 public void UnregisterTimer(TimerEntry timerEntry)
 {
     this._timersToRemove.Add(timerEntry);
 }
Пример #4
0
        void Update()
        {
            int count = this._updatesToRemove.Count;

            for (int i = 0; i < count; i++)
            {
                this._updates.Remove(this._updatesToRemove[i]);
            }
            this._updatesToRemove.Clear();

            count = this._updates.Count;
            for (int i = 0; i < count; i++)
            {
                this._updates[i].Invoke(Time.deltaTime);
            }

            ////////////////schedule

            count = this._schedulesToRemove.Count;
            for (int i = 0; i < count; i++)
            {
                this._schedules.Remove(this._schedulesToRemove[i]);
            }
            this._schedulesToRemove.Clear();

            count = this._schedules.Count;
            for (int i = 0; i < count; i++)
            {
                ScheduleEntry scheduleEntry = this._schedules[i];
                scheduleEntry.OnUpdate(Time.deltaTime);
                if (scheduleEntry.finished)
                {
                    this.UnregisterSchedule(scheduleEntry);
                }
            }

            count = this._schedulesToRemove.Count;
            for (int i = 0; i < count; i++)
            {
                this._schedules.Remove(this._schedulesToRemove[i]);
            }
            this._schedulesToRemove.Clear();

            /////////////////// timer

            count = this._timersToRemove.Count;
            for (int i = 0; i < count; i++)
            {
                this._timers.Remove(this._timersToRemove[i]);
            }
            this._timersToRemove.Clear();

            count = this._timers.Count;
            for (int i = 0; i < count; i++)
            {
                TimerEntry timerEntry = this._timers[i];
                timerEntry.OnUpdate(Time.deltaTime);
                if (timerEntry.finished)
                {
                    this.UnregisterTimer(timerEntry);
                }
            }

            count = this._timersToRemove.Count;
            for (int i = 0; i < count; i++)
            {
                this._timers.Remove(this._timersToRemove[i]);
            }
            this._timersToRemove.Clear();
        }