コード例 #1
0
ファイル: FastTimer.cs プロジェクト: 517752548/-
 /// <summary>
 /// Resume a timer. The main benefit of this over the method on the instance is that you will not get
 /// a <see cref="NullReferenceException"/> if the timer is null.
 /// </summary>
 /// <param name="timer">The timer to resume.</param>
 public static void Resume(FastTimer timer)
 {
     if (timer != null)
     {
         timer.Resume();
     }
 }
コード例 #2
0
ファイル: FastTimer.cs プロジェクト: 517752548/-
 /// <summary>
 /// Pause a timer. The main benefit of this over the method on the instance is that you will not get
 /// a <see cref="NullReferenceException"/> if the timer is null.
 /// </summary>
 /// <param name="timer">The timer to pause.</param>
 public static void Pause(FastTimer timer)
 {
     if (timer != null)
     {
         timer.Pause();
     }
 }
コード例 #3
0
ファイル: FastTimer.cs プロジェクト: 517752548/-
 /// <summary>
 /// Cancels a timer. The main benefit of this over the method on the instance is that you will not get
 /// a <see cref="NullReferenceException"/> if the timer is null.
 /// </summary>
 /// <param name="timer">The timer to cancel.</param>
 public static void Cancel(FastTimer timer)
 {
     if (timer != null)
     {
         timer.Cancel();
     }
 }
コード例 #4
0
ファイル: FastTimer.cs プロジェクト: 517752548/-
    /// <summary>
    /// Register a new timer that should fire an event after a certain amount of time
    /// has elapsed.
    ///
    /// Registered timers are destroyed when the scene changes.
    /// </summary>
    /// <param name="duration">The time to wait before the timer should fire, in seconds.</param>
    /// <param name="onComplete">An action to fire when the timer completes.</param>
    /// <param name="onUpdate">An action that should fire each time the timer is updated. Takes the amount
    /// of time passed in seconds since the start of the timer's current loop.</param>
    /// <param name="isLooped">Whether the timer should repeat after executing.</param>
    /// <param name="useRealTime">Whether the timer uses real-time(i.e. not affected by pauses,
    /// slow/fast motion) or game-time(will be affected by pauses and slow/fast-motion).</param>
    /// <param name="autoDestroyOwner">An object to attach this timer to. After the object is destroyed,
    /// the timer will expire and not execute. This allows you to avoid annoying <see cref="NullReferenceException"/>s
    /// by preventing the timer from running and accessessing its parents' components
    /// after the parent has been destroyed.</param>
    /// <returns>A timer object that allows you to examine stats and stop/resume progress.</returns>
    public static FastTimer Register(float duration, Action onComplete, Action <float> onUpdate = null,
                                     bool isLooped = false, bool useRealTime = false, MonoBehaviour autoDestroyOwner = null)
    {
        // create a manager object to update all the timers if one does not already exist.
        if (_manager == null)
        {
            _manager = FastLib.GetFastTimerManager();
        }

        FastTimer timer = new FastTimer(duration, onComplete, onUpdate, isLooped, useRealTime, autoDestroyOwner);

        FastTimer._manager.RegisterTimer(timer);
        return(timer);
    }
コード例 #5
0
        public void FastTimerNotEnabled_ShouldFire_0TimesPerSecond()
        {
            // Arrange
            var fastTimer = new FastTimer(30)
            {
                Enabled = false
            };

            fastTimer.Elapsed += Callback;
            _callbacks.Clear();

            // Act
            Thread.Sleep(2000);

            // Assert
            _callbacks.Count.Should().Be(0);
        }
コード例 #6
0
        public void FastTimerWithNoCallback_ShouldFire_0TimesPerSecond()
        {
            // Arrange
            var fastTimer = new FastTimer(30)
            {
                Enabled = false
            };

            _callbacks.Clear();

            // Act
            fastTimer.Enabled = true;
            Thread.Sleep(2000);
            fastTimer.Enabled = false;

            // Assert
            _callbacks.Count.Should().Be(0);
        }
コード例 #7
0
        public void FastTimer_ShouldFire_100TimesPerSecond()
        {
            // Arrange
            var fastTimer = new FastTimer(10)
            {
                Enabled = false
            };

            fastTimer.Elapsed += Callback;
            _callbacks.Clear();

            // Act
            fastTimer.Enabled = true;
            Thread.Sleep(2000);
            fastTimer.Enabled = false;

            // Assert (let's have some wiggle room here for timing issues)
            _callbacks.Count.Should().BeInRange(185, 215);
        }
コード例 #8
0
        public void FastTimerWithNoAutoReset_ShouldFire_Once()
        {
            // Arrange
            var fastTimer = new FastTimer(30)
            {
                Enabled   = false,
                AutoReset = false
            };

            fastTimer.Elapsed += Callback;
            _callbacks.Clear();

            // Act
            fastTimer.Enabled = true;
            Thread.Sleep(2000);
            fastTimer.Enabled = false;

            // Assert
            _callbacks.Count.Should().Be(1);
        }
コード例 #9
0
ファイル: FastTimer.cs プロジェクト: 517752548/-
 public static FastTimer AttachTimer(MonoBehaviour behaviour, float duration, Action onComplete,
                                     Action <float> onUpdate = null, bool isLooped = false, bool useRealTime = false)
 {
     return(FastTimer.Register(duration, onComplete, onUpdate, isLooped, useRealTime, behaviour));
 }
コード例 #10
0
ファイル: FastTimerManager.cs プロジェクト: 517752548/-
 public void RegisterTimer(FastTimer timer)
 {
     this._timersToAdd.Add(timer);
 }