Ejemplo n.º 1
0
        public bool FindPath2D(Vector2 startPos, Vector2 endPos, List <Vector2> path)
        {
            var startIndex = this.GetInsidePolyIndex(startPos);

            if (startIndex < 0)
            {
                return(false);
            }
            var endIndex = this.GetInsidePolyIndex(endPos);

            if (endIndex < 0)
            {
                return(false);
            }

            var nodeStart = this.polyNodes[startIndex];
            var nodeEnd   = this.polyNodes[endIndex];

            if (!PolyAStar.FindPath(nodeStart, nodeEnd, this.polyNodes))
            {
                return(false);
            }

            PolyCornerPath.FindPath2D(startPos, endPos, nodeEnd, path);
            return(true);
        }
Ejemplo n.º 2
0
        //==========================================================
        void CalculatePath(Vector3 startPos, Vector3 endPos)
        {
            testPathNodeEnd     = null;
            testPath            = null;
            testStartClosestDis = -1;
            testEndClosestDis   = -1;

            Vector2 startPos2D = new Vector2(startPos.x, startPos.z);
            Vector2 endPos2D   = new Vector2(endPos.x, endPos.z);

            int startIndex = navMesh.GetInsidePolyIndex(startPos2D);

            if (startIndex < 0)
            {
                testStartClosestDis = navMesh.FindClosestEdge2D(startPos2D, out testStartClosest);
            }
            int endIndex = navMesh.GetInsidePolyIndex(endPos2D);

            if (endIndex < 0)
            {
                testEndClosestDis = navMesh.FindClosestEdge2D(endPos2D, out testEndClosest);
            }
            if (testStartClosestDis > 0 || testEndClosestDis > 0)
            {
                return;
            }

            PolyNode nodeStart = navMesh.polyNodes[startIndex];
            PolyNode nodeEnd   = navMesh.polyNodes[endIndex];

            if (!PolyAStar.FindPath(nodeStart, nodeEnd, navMesh.polyNodes))
            {
                return;
            }

            testPath = PolyCornerPath.FindPath2D(startPos2D, endPos2D, nodeEnd);

            testPathNodeEnd = nodeEnd;
        }