示例#1
0
        /// <summary>
        /// Processes queued requests as a coroutine.
        /// </summary>
        /// <param name="maxMillisecondsPerFrame">The maximum milliseconds per frame before yielding.</param>
        /// <returns>
        /// coroutine enumerator
        /// </returns>
        /// <exception cref="System.InvalidOperationException">Cannot process as coroutine when set to async operation.</exception>
        public IEnumerator ProcessRequests(int maxMillisecondsPerFrame)
        {
            if (this.runAsync)
            {
                throw new InvalidOperationException("Cannot process as coroutine when set to async operation.");
            }

            while (!this.runAsync)
            {
                var next = GetNext();
                if (next == null)
                {
                    yield return(null);
                }
                else
                {
                    _stopwatch.Start();

                    next = _directPather.ResolveDirectPath(next);

                    if (_stopwatch.ElapsedMilliseconds > maxMillisecondsPerFrame)
                    {
                        _stopwatch.Reset();
                        yield return(null);
                    }

                    if (next == null)
                    {
                        continue;
                    }

                    var run     = true;
                    var subIter = _engine.ProcessRequestCoroutine(next);

                    while (run)
                    {
                        //Start is called multiple places, due to the enumeration going on in various loops. Start is safe to call multiple times, it will simply do nothing if already started.
                        _stopwatch.Start();
                        run = subIter.MoveNext();

                        if (_stopwatch.ElapsedMilliseconds > maxMillisecondsPerFrame)
                        {
                            _stopwatch.Reset();
                            yield return(null);
                        }
                    }
                }
            }
        }