Example #1
0
        private void UpdateInternal(float deltaTime)
        {
            if (_isPaused)
            {
                return;
            }

            if (_isWaitingForDelay)
            {
                _isWaitingForDelay = _elapsedTime < Delay;

                if (!_isWaitingForDelay)
                {
                    OnStart();
                }
            }
            else
            {
                if (hasMaxDuration && TimeSinceStart > maxDuration)
                {
                    Kill();
                }

                OnUpdate(deltaTime);
            }

            _elapsedTime += deltaTime;
            onUpdate?.Invoke();
        }
Example #2
0
 /// <summary>
 /// Forces the task to stop without invoking the action and without calling OnComplete. OnKill will be invoked.
 /// </summary>
 public void Kill()
 {
     isDone = true;
     onKill?.Invoke();
 }
Example #3
0
        private void UpdateInternal(float deltaTime)
        {
            if (IsDone)
            {
                return;
            }

            if (_isCompletionScheduled || _loopStarted && HasTimedOut())
            {
                Complete();
                return;
            }

            if (_taskType != TaskType.OnCondition)
            {
                if ((!_loopStarted || !_isLooped) && ElapsedTime > _after)
                {
                    action.Invoke();
                    if (!_isLooped)
                    {
                        if (!_completeAfterLastFrame)
                        {
                            Complete();
                        }
                        else
                        {
                            _isCompletionScheduled = true;
                        }
                    }
                    else if (!_loopStarted)
                    {
                        _loopStarted     = true;
                        _loopElapsedTime = 0;
                    }
                }
                else if (_isLooped && _loopStarted)
                {
                    if (_loopElapsedTime > _every)
                    {
                        _loopElapsedTime = 0;

                        if (condition != null && condition())
                        {
                            Complete();
                        }
                        else
                        {
                            action?.Invoke();
                        }
                    }
                    _loopElapsedTime += deltaTime;
                }
            }
            else
            {
                if (condition != null && condition())
                {
                    action?.Invoke();
                    Complete();
                }
            }

            ElapsedTime += deltaTime;
            ElapsedFrames++;
            onUpdate?.Invoke();
        }
Example #4
0
 /// <summary>
 /// Forces the task to complete, invoking the scheduled action and calling OnComplete
 /// </summary>
 public void Complete()
 {
     isDone = true;
     action.Invoke();
     onComplete?.Invoke();
 }
Example #5
0
 public void Complete()
 {
     IsDone = true;
     onComplete?.Invoke();
 }