Esempio n. 1
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, Action Callback, bool bLooping)
        {
            if (!m_Timers.ContainsKey(sTimerName))
            {
                TimerInstance t = new TimerInstance();
                t.fRemainingTime = fTimerDuration;
                t.fTotalTime = fTimerDuration;
                t.iTriggerCount = 0;
                t.OnTimer += Callback;
                t.bLooping = bLooping;
                t.bRemove = false;

                // Add to the pending list for now, will get moved to active list later
                // If it's already in the pending list for some reason, remove the existing one
                if (m_Pending.ContainsKey(sTimerName))
                {
                    m_Pending.Remove(sTimerName);
                }
                m_Pending.Add(sTimerName, t);

                return true;
            }
            else
            {
                return false;
            }
        }
Esempio n. 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, Action Callback, bool bLooping)
        {
            if (!m_Timers.ContainsKey(sTimerName))
            {
                TimerInstance t = new TimerInstance();
                t.fRemainingTime = fTimerDuration;
                t.fTotalTime     = fTimerDuration;
                t.iTriggerCount  = 0;
                t.OnTimer       += Callback;
                t.bLooping       = bLooping;
                t.bRemove        = false;

                // Add to the pending list for now, will get moved to active list later
                // If it's already in the pending list for some reason, remove the existing one
                if (m_Pending.ContainsKey(sTimerName))
                {
                    m_Pending.Remove(sTimerName);
                }
                m_Pending.Add(sTimerName, t);

                return(true);
            }
            else
            {
                return(false);
            }
        }