Exemplo n.º 1
0
        public void Init()
        {
            wpSectionList = new List <WPSection>();

            for (int i = 0; i < wpList.Count; i++)
            {
                Transform wpT = wpList[i];

                //check if this is a platform, BuildManager would have add the component and have them layered
                if (wpT != null)
                {
                    WPSection section = new WPSection(wpT);

                    if (wpT.gameObject.layer == TDTK.GetLayerPlatform())
                    {
                        section.isPlatform       = true;
                        section.platform         = wpT.gameObject.GetComponent <PlatformTD>();
                        section.pathIDOnPlatform = section.platform.AddSubPath(this, i, wpList[i - 1], wpList[i + 1]);

                        if (isLinearPath)
                        {
                            isLinearPath = false;
                        }
                    }
                    else
                    {
                        WPSubPath wpSubPath = wpT.gameObject.GetComponent <WPSubPath>();
                        if (wpSubPath != null)
                        {
                            section.SetPosList(new List <Vector3>(wpSubPath.posList));
                        }
                        else
                        {
                            section.SetPosList(new List <Vector3> {
                                wpT.position
                            });
                        }
                    }

                    wpSectionList.Add(section);
                }
                else
                {
                    wpList.RemoveAt(i);
                    i -= 1;
                }
            }


            if (loop)
            {
                loopPoint = Mathf.Min(wpList.Count - 1, loopPoint);             //looping must be 1 waypoint before the destination
            }
        }
Exemplo n.º 2
0
        void OnDrawGizmos()
        {
            if (showGizmo)
            {
                Gizmos.color = gizmoColor;

                if (Application.isPlaying)
                {
                    List <Vector3> firstSubPath = GetWPSectionPath(0);
                    for (int n = 1; n < firstSubPath.Count; n++)
                    {
                        Gizmos.DrawLine(firstSubPath[n - 1], firstSubPath[n]);
                    }

                    for (int i = 1; i < wpSectionList.Count; i++)
                    {
                        List <Vector3> subPathO = GetWPSectionPath(i - 1);
                        List <Vector3> subPath  = GetWPSectionPath(i);

                        Gizmos.DrawLine(subPathO[subPathO.Count - 1], subPath[0]);
                        for (int n = 1; n < subPath.Count; n++)
                        {
                            Gizmos.DrawLine(subPath[n - 1], subPath[n]);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < wpList.Count - 1; i++)
                    {
                        if (wpList[i] != null && wpList[i + 1] != null)
                        {
                            WPSubPath wpSubPath1 = wpList[i].gameObject.GetComponent <WPSubPath>();
                            WPSubPath wpSubPath2 = wpList[i + 1].gameObject.GetComponent <WPSubPath>();

                            if (wpSubPath1 != null && wpSubPath2 != null)
                            {
                                for (int n = 0; n < wpSubPath1.posList.Count - 1; n++)
                                {
                                    Gizmos.DrawLine(wpSubPath1.posList[n], wpSubPath1.posList[n + 1]);
                                }
                                Gizmos.DrawLine(wpSubPath1.posList[wpSubPath1.posList.Count - 1], wpSubPath2.posList[0]);
                            }
                            else if (wpSubPath1 != null && wpSubPath2 == null)
                            {
                                for (int n = 0; n < wpSubPath1.posList.Count - 1; n++)
                                {
                                    Gizmos.DrawLine(wpSubPath1.posList[n], wpSubPath1.posList[n + 1]);
                                }
                                Gizmos.DrawLine(wpSubPath1.posList[wpSubPath1.posList.Count - 1], wpList[i + 1].position);
                            }
                            else if (wpSubPath1 == null && wpSubPath2 != null)
                            {
                                Gizmos.DrawLine(wpList[i].position, wpSubPath2.posList[0]);
                            }
                            else
                            {
                                Gizmos.DrawLine(wpList[i].position, wpList[i + 1].position);
                            }
                        }
                    }
                }
            }
        }