Exemplo n.º 1
0
 public Timer(float targetTime, object data = null, OnTimerUp callback = null)
 {
     TimePassed = 0.0f;
     TargetTime = targetTime;
     m_firedCallback = false;
     Data = data;
     m_callback = callback;
 }
Exemplo n.º 2
0
 public Timer(float timeGoal, OnTimerUp callback = null)
 {
     TimePassed = 0.0f;
     TimeGoal = timeGoal;
     m_callbackFired = false;
     m_callback = callback;
     Debug.Log(TimeGoal);
     Debug.Log(m_callback);
 }
    private async void RunAsync()
    {
        if (_cancelSource != null)
        {
            _cancelSource.Cancel();
        }
        _cancelSource = new CancellationTokenSource();
        var token = _cancelSource.Token;

        await Task.Run(() =>
        {
            while (_targetTime > DateTime.Now)
            {
                if (token.IsCancellationRequested)
                {
                    return;
                }
            }
            ;
            _synchronizationContext.Post((s) => OnTimerUp?.Invoke(), null);
        }, token);
    }