コード例 #1
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
        /// <summary>
        /// 寻路
        /// </summary>
        /// <param name="id">地图Id</param>
        /// <param name="spos">起点三维坐标</param>
        /// <param name="epos">终点三维坐标</param>
        /// <returns></returns>
        public static bool FindPath(int id, Vector3 spos, Vector3 epos)
        {
            {
                float[] fixPos = fixposition(id, spos);
                if (fixPos != null)
                {
                    spos.y = fixPos[1];
                }
                else
                {
                    Console.WriteLine(string.Concat("错误:", ($"Recast寻路 FindPath Error:- 起点非法 - spos:{spos} - MapId:{id}")));
                }

                SPos = spos;
            }
            {
                float[] fixPos = fixposition(id, epos);
                if (fixPos != null)
                {
                    epos.y = fixPos[1];
                }
                else
                {
                    Console.WriteLine(string.Concat("错误:", ($"Recast寻路 FindPath Error:- 终点非法 - epos:{epos} - MapId:{id}")));
                }

                EPos = epos;
            }
            dtStatus status = (dtStatus)recast_findpath(id, new[] { -spos.x, spos.y, spos.z }, new[] { -epos.x, epos.y, epos.z });

            if (dtStatusFailed(status))
            {
                dtStatus statusDetail  = status & dtStatus.DT_STATUS_DETAIL_MASK;
                string   _strLastError = $"Recast寻路 FindPath Error:寻路失败!错误码<" + statusDetail + $"> - MapId:{id}";
                if (statusDetail == dtStatus.DT_COORD_INVALID)
                {
                    _strLastError += " - 坐标非法!From<" + spos + "> To<" + epos + $"> - MapId:{id}";
                }
                Console.WriteLine(string.Concat("错误:", _strLastError));
                return(false);
            }
            else if (dtStatusInProgress(status))
            {
                string _strLastError = $"Recast寻路 Error:寻路尚未结束!- MapId:{id}";
                Console.WriteLine(string.Concat("错误:", _strLastError));
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
        /// <summary>
        /// 射线检测
        /// </summary>
        /// <param name="id">地图Id</param>
        /// <param name="spos">起点三维坐标</param>
        /// <param name="epos">终点三维坐标</param>
        /// <returns></returns>
        public static bool Raycast(int id, Vector3 spos, Vector3 epos)
        {
            dtStatus status = (dtStatus)recast_raycast(id, new float[] { -spos.x, spos.y, spos.z }, new float[] { -epos.x, epos.y, epos.z });

            if (dtStatusFailed(status))
            {
                dtStatus statusDetail  = status & dtStatus.DT_STATUS_DETAIL_MASK;
                string   _strLastError = "Recast寻路 Raycast Error:寻路失败!错误码<" + statusDetail + $"> - MapId:{id}";
                if (statusDetail == dtStatus.DT_COORD_INVALID)
                {
                    _strLastError += " - 坐标非法!From<" + spos + "> To<" + epos + $"> - MapId:{id}";
                }
                Console.WriteLine(string.Concat("错误:", _strLastError));
                return(false);
            }
            else if (dtStatusInProgress(status))
            {
                string _strLastError = $"Recast寻路 Error:寻路尚未结束! - MapId:{id}";
                Console.WriteLine(string.Concat("错误:", _strLastError));
                return(false);
            }

            return(true);
        }
コード例 #3
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
 // Returns true if specific detail is set.
 public static bool dtStatusDetail(dtStatus status, uint detail)
 {
     return(((uint)status & detail) != 0);
 }
コード例 #4
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
 // Returns true of status is in progress.
 public static bool dtStatusInProgress(dtStatus status)
 {
     return((status & dtStatus.DT_IN_PROGRESS) != 0);
 }
コード例 #5
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
 // Returns true of status is failure.
 public static bool dtStatusFailed(dtStatus status)
 {
     return((status & dtStatus.DT_FAILURE) != 0);
 }
コード例 #6
0
ファイル: RecastInterface.cs プロジェクト: yfgumaths/ET
 // Returns true of status is success.
 public static bool dtStatusSucceed(dtStatus status)
 {
     return((status & dtStatus.DT_SUCCESS) != 0);
 }