Пример #1
0
        /// <summary>
        /// Finds a path from the start point to the end point using the <see cref="path"/> object.
        /// </summary>
        /// <remarks>
        /// <para
        /// ><b>Warning</b>: The path object must be available before calling this method.
        /// </para>
        /// <para>
        /// This method will perform full planning only if <paramref name="start"/> or
        /// <paramref name="end"/> is outside the existing path.
        /// </para>
        /// <para>
        /// The input points are all expected to be valid. (E.g. polyRef != 0)
        /// </para>
        /// </remarks>
        /// <param name="start">
        /// A valid navigation mesh point representing the start of the path.
        /// </param>
        /// <param name="end">
        /// A valid navigation mesh point representing the end of the path.
        /// </param>
        /// <returns>The length of the path, or -1 on failure.</returns>
        public int PlanPath(NavmeshPoint start, NavmeshPoint end)
        {
            path.straightCount = 0;

            if (start.polyRef == 0 || end.polyRef == 0 || path == null)
            {
                return(-1);
            }

            if (start.polyRef == end.polyRef)
            {
                // Debug.Log("Replan Path: Points in same poly.");
                path.pathCount = 1;
                path.path[0]   = start.polyRef;
                data.navStatus = NavStatus.Sucess;
                return(1);
            }

            if (path.FixPath(start.polyRef, end.polyRef))
            {
                // Debug.Log("Replan Path: Fixed existing path");
                data.navStatus = NavStatus.Sucess;
                return(path.pathCount);
            }

            // Debug.Log("Replace Path: Full query.");
            data.navStatus = navGroup.query.FindPath(start
                                                     , end
                                                     , navGroup.filter
                                                     , path.path
                                                     , out path.pathCount);

            return(path.pathCount);
        }