コード例 #1
0
ファイル: Timer.cs プロジェクト: shalynnho/airplane
 /// <summary>
 /// AddTimer will add a new timer provided a timer of the same name does not already exist.
 /// </summary>
 /// <param name="sTimerName">Name of timer to be added</param>
 /// <param name="fTimerDuration">Duration timer should last, in seconds</param>
 /// <param name="Callback">Call back delegate which should be called when the timer expires</param>
 /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param>
 /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns>
 public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping)
 {
     if (!m_kTimers.ContainsKey(sTimerName))
     {
         TimerInstance t = new TimerInstance();
         t.fRemainingTime = fTimerDuration;
         t.fTotalTime = fTimerDuration;
         t.iTriggerCount = 0;
         t.OnTimer += Callback;
         t.bLooping = bLooping;
         t.bRemove = false;
         m_kTimers.Add(sTimerName, t);
         return true;
     }
     else
     {
         return false;
     }
 }
コード例 #2
0
        /// <summary>
        /// AddTimer will add a new timer provided a timer of the same name does not already exist.
        /// </summary>
        /// <param name="sTimerName">Name of timer to be added</param>
        /// <param name="fTimerDuration">Duration timer should last, in seconds</param>
        /// <param name="Callback">Call back delegate which should be called when the timer expires</param>
        /// <param name="bLooping">Whether the timer should loop infinitely, or should fire once and remove itself</param>
        /// <returns>Returns true if the timer was successfully added, false if it wasn't</returns>
        public bool AddTimer(string sTimerName, float fTimerDuration, TimerDelegate Callback, bool bLooping)
        {
            TimerInstance newTimer = new TimerInstance();
            if (m_kTimers.ContainsKey(sTimerName) == true)
            {
                return false;
            }
            else
            {
                newTimer.sTimerName = sTimerName;
                newTimer.fTotalTime = fTimerDuration;
                newTimer.fRemainingTime = fTimerDuration;
                newTimer.bRemove = false;
                newTimer.OnTimer += Callback;
                newTimer.bLooping = bLooping;
                newTimer.iTriggerCount = 0;

                m_kTimers.Add(sTimerName, newTimer);

                return true;
            }
        }