Exemplo n.º 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]);
            }
        }
Exemplo n.º 2
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;
        }