Esempio n. 1
0
    //Call this function to calculate a path
    public static IEnumerator StartPathYield(Path p, Seeker s)
    {
        if (!p.error)
        {

            while (activePath || active.pathsThisFrame >= active.maxPathsPerFrame)
            {
                if (active.lastPathFrame != Time.frameCount && !activePath)
                {
                    active.pathsThisFrame = 0;
                    active.lastPathFrame = Time.frameCount;
                    break;
                }
                yield return 0;
            }
            active.lastPathFrame = Time.frameCount;
            active.pathsThisFrame++;
            //Debug.Log ("Pathfinding started, calculating...\nPathfinding started at frame "+Time.frameCount +"  "+active.pathsThisFrame);
            activePath = true;
            active.lastPath = p;
            if (!p.error)
            {
                p.Init();
            }

            //The error can turn up in the Init function
            if (!p.error && !p.foundEnd)
            {
                p.Calc();//Comment this if you want a bit higher framerate @Performance
                while (!p.foundEnd && !p.error)
                {
                    yield return 0;
                    active.pathsThisFrame = 1;
                    p.Calc();
                }

            }
            activePath = false;
        }
        s.OnComplete(p);
    }