示例#1
0
 private string getTimerString(TimerHandle th)
 {
     string pattern = "<size=13>Status:<color={0}>{1}</color>\tTag:{2} </size>";
     return string.Format(pattern,
                          th.bPaused? "red" : "green",
                          th.bPaused? "Paused":"Running",
                          th.tag
                          );
 }
示例#2
0
        public static TimerHandle AddTimer(this MonoBehaviour mb, TimerFunc func, float delay, float interval, int maxCount, string tag = "defaultTag")
        {
            TimerHandle th = new TimerHandle();
            th.func = func;
            th.delay = delay;
            th.interval = interval;
            th.maxCount = maxCount;
            th.tag = tag;

            mb.StartCoroutine(_timer(th));
            return th;
        }
示例#3
0
        /// <summary>
        /// Adds the timer to GLOBAL
        /// </summary>
        /// <returns>The timer handle.</returns>
        /// <param name="func">Func.</param>
        /// <param name="delay">Delay.</param>
        /// <param name="interval">Interval.</param>
        /// <param name="maxCount">Max count.</param>
        /// <param name="tag">Tag, only for debug.</param>
        public static TimerHandle addTimerGlobal(TimerFunc func, float delay, float interval, int maxCount, string tag = "defaultTag")
        {
            if (_Instance == null)
            {
                GameObject go = new GameObject("Timer");
                DontDestroyOnLoad(go);
                _Instance           = go.AddComponent <Timer>();
                _Instance.timerName = "Global";
            }
            TimerHandle th = _Instance.addTimerInternal(func, delay, interval, maxCount, tag);

            return(th);
        }
示例#4
0
        private IEnumerator _timer(TimerHandle th)
        {
            int countNow = 0;

            if (th.delay > 0f)
            {
                yield return(new WaitForSeconds(th.delay));
            }
            while (th.maxCount != 0)
            {
                if (th.bDead == true)
                {
                    break;
                }
                if (bPaused == true || th.bPaused == true)
                {
                    yield return(0);
                }
                else
                {
                    if (th.maxCount != INFINITE)
                    {
                        ++countNow;
                    }
                                        #if UNITY_EDITOR
                    ++th.countNow;
                                        #endif
                    if (th.func())                      //If TimerFunc return true then end Timer Immediately.
                    {
                        break;
                    }
                    if (th.maxCount != INFINITE && countNow >= th.maxCount)
                    {
                        break;
                    }
                    yield return(new WaitForSeconds(th.interval));
                }
            }
            //clean up timer
            th.bDead = true;
            if (th.completeCB != null)
            {
                th.completeCB();
            }
                        #if UNITY_EDITOR
            timerHandleList.Remove(th);
                        #endif
        }
示例#5
0
        public TimerHandle addTimerInternal(TimerFunc func, float delay, float interval, int maxCount, string tag = "defaultTag")
        {
            TimerHandle th = new TimerHandle();

            th.func     = func;
            th.delay    = delay;
            th.interval = interval;
            th.maxCount = maxCount;
            th.tag      = tag;

            StartCoroutine(_timer(th));
                        #if UNITY_EDITOR
            th.countNow = 0;
            timerHandleList.AddLast(th);
                        #endif
            return(th);
        }
示例#6
0
 private static IEnumerator _timer(TimerHandle th)
 {
     int countNow = 0;
     if(th.delay > 0f)
         yield return new WaitForSeconds(th.delay);
     while(th.maxCount != 0)
     {
         if(th.bDead == true)
             break;
         if(th.bPaused == true)
         {
             yield return 0;
         }
         else
         {
             if(th.maxCount != Timer.INFINITE)
             {
                 ++countNow;
             }
             #if UNITY_EDITOR
             ++th.countNow;
             #endif
             if(th.func())	//If TimerFunc return true then end Timer Immediately.
                 break;
             if(th.maxCount != Timer.INFINITE && countNow >= th.maxCount)
                 break;
             yield return new WaitForSeconds(th.interval);
         }
     }
     //clean up timer
     th.bDead = true;
     if(th.completeCB != null)
     {
         th.completeCB();
     }
 }
示例#7
0
        public TimerHandle addTimerInternal(TimerFunc func, float delay, float interval, int maxCount, string tag = "defaultTag")
        {
            TimerHandle th = new TimerHandle();
            th.func = func;
            th.delay = delay;
            th.interval = interval;
            th.maxCount = maxCount;
            th.tag = tag;

            StartCoroutine(_timer(th));
            #if UNITY_EDITOR
            th.countNow = 0;
            timerHandleList.AddLast(th);
            #endif
            return th;
        }