예제 #1
0
        /// <summary>
        /// Update all running coroutines. Performs cleanup as well.
        /// </summary>
        /// <returns>Whether any routines were updated.</returns>
        public bool Update()
        {
            lock (this)
            {
                // If no routines are running, do nothing.
                if (_runningRoutines.Count <= 0)
                {
                    return(false);
                }

                for (var i = 0; i < _runningRoutines.Count; i++)
                {
                    IRoutineWaiter current = _runningRoutines[i];

                    // Update the current delay of the coroutine.
                    current?.Update();

                    // Check if the current delay is finished. If not, skip.
                    if (current != null && current.Finished != true)
                    {
                        continue;
                    }

                    // Remove the routine from the list and decrement.
                    _runningRoutines.RemoveAt(i);
                    i--;
                }

                return(true);
            }
        }
예제 #2
0
        public virtual void Update()
        {
            var allDone = true;

            for (var i = 0; i < _waiters.Length; i++)
            {
                IRoutineWaiter waiter = _waiters[i];
                waiter.Update();
                allDone = allDone && waiter.Finished;
            }

            Finished = allDone;
        }
예제 #3
0
        private void Run()
        {
            if (Finished)
            {
                return;
            }

            // Update the waiter.
            _currentWaiter?.Update();

            // Check if the current waiter is finished. If not, continue waiting.
            if (_currentWaiter != null && _currentWaiter?.Finished != true)
            {
                return;
            }

            // Increment the routine.
            bool?  incremented  = _routine?.MoveNext();
            object currentYield = _routine?.Current;

            if (incremented == true)
            {
                switch (currentYield)
                {
                // Check if a delay, and add it as the routine's delay.
                case IRoutineWaiter routineDelay:
                    _currentWaiter = routineDelay;
                    break;

                // Check if adding a subroutine.
                case IEnumerator subroutine:
                    _currentWaiter = new Coroutine(subroutine);
                    break;
                }

                // If the delay is some other object it will delay execution by one loop.
            }
            else
            {
                _currentWaiter = null;
                _routine       = null;
            }
        }
예제 #4
0
 public PassiveRoutineObserver(IRoutineWaiter wrap)
 {
     Debug.Assert(wrap != null);
     _wrap = wrap;
 }