示例#1
0
        /// <summary>
        /// Starts the timer
        ///
        /// Advanced: should not be called for owner called update model
        /// </summary>
        public void Start()
        {
            this.state = State.Running;

            // If starting for the first time, just grab the current time.
            startTime = clock == ClockType.WallClock ? Time.WallClockTotalSeconds : Time.GameTimeTotalSeconds;

            GameTimerManager.AttachTimer(this);
        }
示例#2
0
        /// <summary>
        /// Restarts the timer but resets the start time based on the previous start time.
        /// This prevents errors from accumulating since timeout values don't sync perfectly
        /// with frame times.
        /// </summary>
        /// <param name="sync">If sync is true, we want to restart the timer in such a way as to take the previous start time into account.  If sync is false, we want to just start from "now".</param>
        public void ReStart(bool sync)
        {
            this.state = State.Running;

            // Need to adjust start time so that it is in range (curTime - seconds, curTime]
            double curTime = clock == ClockType.WallClock ? Time.WallClockTotalSeconds : Time.GameTimeTotalSeconds;

            if (sync)
            {
                while (startTime <= curTime)
                {
                    startTime += seconds;
                }
                startTime -= seconds;
            }
            else
            {
                startTime = curTime;
            }

            GameTimerManager.AttachTimer(this);
        }