コード例 #1
0
    private IEnumerator StartContinuousCoroutine(float seconds, TimerElapsedCallback t)
    {
        Debug.Log("StartContinousCoroutine");

        long timeElapsed = 0;

        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        while (true)
        {
            sw.Start();
            yield return(new WaitForSeconds(seconds));

            sw.Stop();

            timeElapsed += sw.ElapsedMilliseconds;

            t?.Invoke(timeElapsed);
        }
    }
コード例 #2
0
    //the coroutine thats actually run
    private IEnumerator StartCountdownCoroutine(float startValue, float waitForDelay, float countDownBy, TimerElapsedCallback t, TimerFinished tf)
    {
        Debug.Log("StartCountdownCoroutine");

        //stopwatch to track time elapsed
        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

        while (startValue > 0)
        {
            sw.Start();

            yield return(new WaitForSeconds(waitForDelay));

            //update 'time-remaining'
            startValue -= countDownBy;

            sw.Stop();

            //callback for interval
            t?.Invoke(sw.ElapsedMilliseconds);
        }

        //callback for end of timer
        tf?.Invoke();

        Debug.Log("Timer finished " + sw.ElapsedMilliseconds);
    }
コード例 #3
0
 //start timer with full customisable
 public void StartTimer(float startValue, float waitForDelay, float countDownBy, TimerElapsedCallback t, TimerFinished tf)
 {
     Debug.Log("StartTimer2");
     coroutine = StartCoroutine(StartCountdownCoroutine(startValue, waitForDelay, countDownBy, t, tf));
 }
コード例 #4
0
 //start timer for seconds with default parameters
 public void StartTimer(float delayInSeconds, TimerElapsedCallback t, TimerFinished tf)
 {
     Debug.Log("StartTimer");
     coroutine = StartCoroutine(StartCountdownCoroutine(delayInSeconds, delayInSeconds, delayInSeconds, t, tf));
 }
コード例 #5
0
 public void StartTimer(float seconds, TimerElapsedCallback t)
 {
     Debug.Log("StartContinousTimer");
     coroutine = StartCoroutine(StartContinuousCoroutine(seconds, t));
 }