示例#1
0
    public static UniTimer Create(float _interval, float _freq, Action <UniTimer> _callUpdate, Action <UniTimer> _callBack)
    {
        UniTimer timer = new UniTimer();

        timer.Start(_interval, _freq, _callUpdate, _callBack);
        return(timer);
    }
示例#2
0
 private void RemoveTimer(UniTimer _timer)
 {
     if (mTimers.Contains(_timer))
     {
         mTimers.Remove(_timer);
     }
 }
 public void AddTimer(UniTimer _timer)
 {
     _timer.mCallTime = 0f;
     _timer.mOverTime = 0f;
     if (!mTimers.Contains(_timer))
     {
         mTimers.Add(_timer);
     }
 }
示例#4
0
 public void AddTimer(UniTimer _timer)
 {
     _timer.mCallTime = 0f;
     _timer.mOverTime = 0f;
     if (!mTimers.Contains(_timer))
     {
         mTimers.Add(_timer);
     }
 }
示例#5
0
    void CallBackTimer()
    {
        if (mEndTimers.Count <= 0)
        {
            return;
        }
        UniTimer timer = mEndTimers.Dequeue();

        if (timer != null && timer.mCallBack != null)
        {
            timer.mCallBack(timer);
        }
    }
示例#6
0
 void UpdateTimer()
 {
     if (mTimers.Count <= 0)
     {
         return;
     }
     for (int i = 0; i < mTimers.Count;)
     {
         UniTimer timer = mTimers[i];
         if (timer.mIsPaused || timer.mIsDeleted)
         {
             ++i;
         }
         else
         {
             if (timer.mFreq > 0)
             {
                 timer.mCallTime += mReqRate;
             }
             timer.mOverTime += mReqRate;
             if (timer.mOverTime >= timer.mInterval &&
                 timer.mInterval >= 0)
             {
                 RemoveTimer(timer);
                 mEndTimers.Enqueue(timer);
             }
             else
             {
                 if (timer.mFreq > 0 &&
                     (timer.mIsInvokeNow || timer.mCallTime >= timer.mFreq) &&
                     timer.mCallUpdate != null)
                 {
                     timer.mIsInvokeNow = false;
                     timer.mCallTime    = 0f;
                     timer.mCallUpdate(timer);
                 }
                 ++i;
             }
         }
     }
     /////////////////////////清除标记为删除的事件///////////////////////////
     for (int i = mTimers.Count - 1; i >= 0; i--)
     {
         if (mTimers[i].mIsDeleted)
         {
             RemoveTimer(mTimers[i]);
         }
     }
 }
示例#7
0
 private void init(float time, bool reverse)
 {
     if (IsTicking)
     {
         return;
     }
     IsTicking = true;
     TotalTime = time;
     mReverse  = reverse;
     if (mReverse)
     {
         NowTime = time;
     }
     else
     {
         NowTime = 0;
     }
     if (mTimer != null)
     {
         mTimer.Stop();
         mTimer.Start(mTotalTime, mFreq, (t) =>
         {
             tick();
         },
                      (t) =>
         {
             end();
         });
     }
     else
     {
         mTimer = UniTimer.Create(mTotalTime, mFreq, (t) =>
         {
             tick();
         },
                                  (t) =>
         {
             end();
         });
     }
 }
 private void RemoveTimer(UniTimer _timer)
 {
     if (mTimers.Contains(_timer))
     {
         mTimers.Remove(_timer);
     }
 }
 public static UniTimer Create(float _interval, float _freq, Action<UniTimer> _callUpdate, Action<UniTimer> _callBack)
 {
     UniTimer timer = new UniTimer();
     timer.Start(_interval, _freq, _callUpdate, _callBack);
     return timer;
 }
示例#10
0
 private void init(float time, bool reverse)
 {
     if (IsTicking) return;
     IsTicking = true;
     TotalTime = time;
     mReverse = reverse;
     if (mReverse)
     {
         NowTime = time;
     }
     else
     {
         NowTime = 0;
     }
     if (mTimer != null)
     {
         mTimer.Stop();
         mTimer.Start(mTotalTime, mFreq, (t) =>
         {
             tick();
         },
         (t) =>
         {
             end();
         });
     }
     else
     {
         mTimer = UniTimer.Create(mTotalTime, mFreq, (t) =>
         {
             tick();
         },
         (t) =>
         {
             end();
         });
     }
 }