Example #1
0
        IEnumerator DemoMultiTargetPath()
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, null);

            lastPath = mp;
            AstarPath.StartPath(mp);
            yield return(StartCoroutine(mp.WaitForPath()));

            List <GameObject> unused = new List <GameObject>(lastRender);

            lastRender.Clear();

            for (int i = 0; i < mp.vectorPaths.Length; i++)
            {
                if (mp.vectorPaths[i] == null)
                {
                    continue;
                }

                List <Vector3> vpath = mp.vectorPaths[i];

                GameObject ob = null;
                if (unused.Count > i && unused[i].GetComponent <LineRenderer>() != null)
                {
                    ob = unused[i];
                    unused.RemoveAt(i);
                }
                else
                {
                    ob = new GameObject("LineRenderer_" + i, typeof(LineRenderer));
                }

                LineRenderer lr = ob.GetComponent <LineRenderer>();
                lr.sharedMaterial = lineMat;
#if UNITY_5_5_OR_NEWER
                lr.startWidth = lineWidth;
                lr.endWidth   = lineWidth;
#if UNITY_2017_1_OR_NEWER
                lr.positionCount = vpath.Count;
#else
                lr.numPositions = vpath.Count;
#endif
#else
                lr.SetWidth(lineWidth, lineWidth);
                lr.SetVertexCount(vpath.Count);
#endif

                for (int j = 0; j < vpath.Count; j++)
                {
                    lr.SetPosition(j, vpath[j] + pathOffset);
                }

                lastRender.Add(ob);
            }

            for (int i = 0; i < unused.Count; i++)
            {
                Destroy(unused[i]);
            }
        }
Example #2
0
    /** Starts a Multi Target Path from multiple start points to a single target point.
     * A Multi Target Path will search from all start points to the target point in one search and will return all paths if \a pathsForAll is true, or only the shortest one if \a pathsForAll is false.\n
     *
     * \param startPoints	The start points of the path
     * \param end			The end point of the path
     * \param pathsForAll	Indicates whether or not a path from all start points should be searched for or only to the closest one
     * \param callback		The function to call when the path has been calculated
     * \param graphMask		Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
     *
     * \a callback and #pathCallback will be called when the path has completed. \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
     * \astarpro
     * \see Pathfinding.MultiTargetPath
     * \see \ref MultiTargetPathExample.cs "Example of how to use multi-target-paths"
     */
    public MultiTargetPath StartMultiTargetPath(Vector3[] startPoints, Vector3 end, bool pathsForAll, OnPathDelegate callback = null, int graphMask = -1)
    {
        MultiTargetPath p = MultiTargetPath.Construct(startPoints, end, null, null);

        p.pathsForAll = pathsForAll;
        return(StartMultiTargetPath(p, callback, graphMask));
    }
Example #3
0
    public MultiTargetPath StartMultiTargetPath(Vector3 start, Vector3[] endPoints, bool pathsForAll, OnPathDelegate callback = null, int graphMask = -1)
    {
        MultiTargetPath multiTargetPath = MultiTargetPath.Construct(start, endPoints, null, null);

        multiTargetPath.pathsForAll = pathsForAll;
        return(this.StartMultiTargetPath(multiTargetPath, callback, graphMask));
    }
    /** Starts a path specified by PathTypesDemo.activeDemo */
    public void DemoPath()
    {
        Path p = null;

        if (activeDemo == 0)
        {
            p = ABPath.Construct(start.position, end.position, OnPathComplete);
        }
        else if (activeDemo == 1)
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == 2)
        {
            RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
            rp.spread        = spread;
            rp.aimStrength   = aimStrength;
            rp.aim           = end.position;
            rp.replaceChance = replaceChance;

            p = rp;
        }
        else if (activeDemo == 3)
        {
            FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength   = aimStrength;
            fp.replaceChance = replaceChance;
            fp.spread        = spread;

            p = fp;
        }
        else if (activeDemo == 4)
        {
            ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete);

            p = constPath;
        }
        else if (activeDemo == 5)
        {
            FloodPath fp = FloodPath.Construct(end.position, null);
            lastFlood = fp;
            p         = fp;
        }
        else if (activeDemo == 6 && lastFlood != null)
        {
            FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete);


            p = fp;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
Example #5
0
        // Token: 0x060029ED RID: 10733 RVA: 0x001C233C File Offset: 0x001C053C
        private IEnumerator DemoMultiTargetPath()
        {
            MultiTargetPath mp = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, null);

            this.lastPath = mp;
            AstarPath.StartPath(mp, false);
            yield return(base.StartCoroutine(mp.WaitForPath()));

            List <GameObject> list = new List <GameObject>(this.lastRender);

            this.lastRender.Clear();
            for (int i = 0; i < mp.vectorPaths.Length; i++)
            {
                if (mp.vectorPaths[i] != null)
                {
                    List <Vector3> list2 = mp.vectorPaths[i];
                    GameObject     gameObject;
                    if (list.Count > i && list[i].GetComponent <LineRenderer>() != null)
                    {
                        gameObject = list[i];
                        list.RemoveAt(i);
                    }
                    else
                    {
                        gameObject = new GameObject("LineRenderer_" + i, new Type[]
                        {
                            typeof(LineRenderer)
                        });
                    }
                    LineRenderer component = gameObject.GetComponent <LineRenderer>();
                    component.sharedMaterial = this.lineMat;
                    component.startWidth     = this.lineWidth;
                    component.endWidth       = this.lineWidth;
                    component.positionCount  = list2.Count;
                    for (int j = 0; j < list2.Count; j++)
                    {
                        component.SetPosition(j, list2[j] + this.pathOffset);
                    }
                    this.lastRender.Add(gameObject);
                }
            }
            for (int k = 0; k < list.Count; k++)
            {
                UnityEngine.Object.Destroy(list[k]);
            }
            yield break;
        }
Example #6
0
    /** Starts a path specified by PathTypesDemo.activeDemo */
    void DemoPath()
    {
        Path p = null;

        if (activeDemo == DemoMode.ABPath)
        {
            p = ABPath.Construct(start.position, end.position, OnPathComplete);

            if (agents != null && agents.Length > 0)
            {
                List <Vector3> pts = Pathfinding.Util.ListPool <Vector3> .Claim(agents.Length);

                Vector3 avg = Vector3.zero;
                for (int i = 0; i < agents.Length; i++)
                {
                    pts.Add(agents[i].transform.position);
                    avg += pts[i];
                }
                avg /= pts.Count;
                for (int i = 0; i < agents.Length; i++)
                {
                    pts[i] -= avg;
                }

                Pathfinding.PathUtilities.GetPointsAroundPoint(end.position, AstarPath.active.graphs[0] as IRaycastableGraph, pts, 0, 0.2f);
                for (int i = 0; i < agents.Length; i++)
                {
                    if (agents[i] == null)
                    {
                        continue;
                    }

                    agents[i].target.position = pts[i];
                    agents[i].UpdatePath();
                }
            }
        }
        else if (activeDemo == DemoMode.MultiTargetPath)
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == DemoMode.RandomPath)
        {
            RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
            rp.spread      = spread;
            rp.aimStrength = aimStrength;
            rp.aim         = end.position;

            p = rp;
        }
        else if (activeDemo == DemoMode.FleePath)
        {
            FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength = aimStrength;
            fp.spread      = spread;

            p = fp;
        }
        else if (activeDemo == DemoMode.ConstantPath)
        {
            StartCoroutine(CalculateConstantPath());
            p = null;
        }
        else if (activeDemo == DemoMode.FloodPath)
        {
            FloodPath fp = FloodPath.Construct(end.position, null);
            lastFlood = fp;
            p         = fp;
        }
        else if (activeDemo == DemoMode.FloodPathTracer && lastFlood != null)
        {
            FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete);

            p = fp;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
Example #7
0
    public void DemoPath()
    {
        Path path = null;

        if (this.activeDemo == 0)
        {
            path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete));
            if (this.agents != null && this.agents.Length > 0)
            {
                List <Vector3> list = ListPool <Vector3> .Claim(this.agents.Length);

                Vector3 vector = Vector3.zero;
                for (int i = 0; i < this.agents.Length; i++)
                {
                    list.Add(this.agents[i].transform.position);
                    vector += list[i];
                }
                vector /= (float)list.Count;
                for (int j = 0; j < this.agents.Length; j++)
                {
                    List <Vector3> list2;
                    int            index;
                    (list2 = list)[index = j] = list2[index] - vector;
                }
                PathUtilities.GetPointsAroundPoint(this.end.position, AstarPath.active.graphs[0] as IRaycastableGraph, list, 0f, 0.2f);
                for (int k = 0; k < this.agents.Length; k++)
                {
                    if (!(this.agents[k] == null))
                    {
                        this.agents[k].target.position = list[k];
                        this.agents[k].UpdatePath();
                    }
                }
            }
        }
        else if (this.activeDemo == 1)
        {
            MultiTargetPath multiTargetPath = MultiTargetPath.Construct(this.multipoints.ToArray(), this.end.position, null, new OnPathDelegate(this.OnPathComplete));
            path = multiTargetPath;
        }
        else if (this.activeDemo == 2)
        {
            RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
            randomPath.spread      = this.spread;
            randomPath.aimStrength = this.aimStrength;
            randomPath.aim         = this.end.position;
            path = randomPath;
        }
        else if (this.activeDemo == 3)
        {
            FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
            fleePath.aimStrength = this.aimStrength;
            fleePath.spread      = this.spread;
            path = fleePath;
        }
        else if (this.activeDemo == 4)
        {
            base.StartCoroutine(this.Constant());
            path = null;
        }
        else if (this.activeDemo == 5)
        {
            FloodPath floodPath = FloodPath.Construct(this.end.position, null);
            this.lastFlood = floodPath;
            path           = floodPath;
        }
        else if (this.activeDemo == 6 && this.lastFlood != null)
        {
            FloodPathTracer floodPathTracer = FloodPathTracer.Construct(this.end.position, this.lastFlood, new OnPathDelegate(this.OnPathComplete));
            path = floodPathTracer;
        }
        if (path != null)
        {
            AstarPath.StartPath(path, false);
            this.lastPath = path;
        }
    }