Exemplo n.º 1
0
        IEnumerator ComputeAsync(Vector2 startPos, Vector2 endPos, int stepIterations)
        {
            m_isComputingPath = true;
            IEnumerator coroutine  = PathFinding.GetRouteFromToAsync(startPos, endPos);
            bool        isFinished = false;

            do
            {
                for (int i = 0; i < stepIterations && !isFinished; ++i)
                {
                    if (coroutine.Current is IEnumerator)
                    {
                        if (!(coroutine.Current as IEnumerator).MoveNext())
                        {
                            isFinished = !coroutine.MoveNext();
                        }
                    }
                    else
                    {
                        isFinished = !coroutine.MoveNext();
                    }
                }
                yield return(null);
            }while (!isFinished);
            //Debug.Log("GetRouteFromToAsync execution time(ms): " + (Time.realtimeSinceStartup - now) * 1000);
            m_pathNodes = coroutine.Current as LinkedList <IPathNode>;
            ProcessComputedPath();
            m_isComputingPath = false;
            if (OnComputedPath != null)
            {
                OnComputedPath(this);
            }
            yield return(null);
        }
Exemplo n.º 2
0
        IEnumerator ComputeAsync(Vector2 startPos, Vector2 endPos, int stepIterations)
        {
            m_isComputingPath = true;
            // start and endPos are swapped because the result linkedlist is reversed
            IEnumerator coroutine  = PathFinding.GetRouteFromToAsync(endPos, startPos);
            bool        isFinished = false;

            do
            {
                for (int i = 0; i < stepIterations && !isFinished; ++i)
                {
                    isFinished = !coroutine.MoveNext();
                }
                yield return(null);
            }while (!isFinished);
            //Debug.Log("GetRouteFromToAsync execution time(ms): " + (Time.realtimeSinceStartup - now) * 1000);
            PathFinding.FindingParams findingParams = (PathFinding.FindingParams)coroutine.Current;
            m_pathNodes = findingParams.computedPath;
            ProcessComputedPath();
            m_isComputingPath = false;
            if (OnComputedPath != null)
            {
                OnComputedPath(this);
            }
            yield return(null);
        }