コード例 #1
0
 /// <summary>
 /// 初始化寻路引擎
 /// </summary>
 public void Awake()
 {
     RecastInterface.Init();
     //TODO 先直接在这里强行初始化地图
     LoadMapNavData(10001, Moba5V5MapNavDataPath.ToCharArray());
     // // 读取体素数据
     // VoxelFile = new VoxelFile();
 }
コード例 #2
0
        public override void Dispose()
        {
            if (this.IsDisposed)
            {
                return;
            }

            base.Dispose();
            RecastInterface.Fini();
        }
コード例 #3
0
 public void CalculatePath(Vector3 from, Vector3 to, List <Vector3> result)
 {
     if (RecastInterface.FindPath(this.MapId, from, to))
     {
         RecastInterface.Smooth(this.MapId, 2f, 0.5f);
         {
             int     smoothCount = 0;
             float[] smooths     = RecastInterface.GetPathSmooth(this.MapId, out smoothCount);
             for (int i = 0; i < smoothCount; ++i)
             {
                 Vector3 node = new Vector3(smooths[i * 3], smooths[i * 3 + 1], smooths[i * 3 + 2]);
                 result.Add(node);
             }
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// 加载一个Map的数据
        /// </summary>
        public void LoadMapNavData(int mapId, char[] navDataPath)
        {
            if (m_RecastPathProcessorDic.ContainsKey(mapId))
            {
                Log.Warning($"已存在Id为{mapId}的地图Nav数据,请勿重复加载!");
                return;
            }

            if (RecastInterface.LoadMap(mapId, navDataPath))
            {
                RecastPathProcessor recastPathProcessor = Entity.Create <RecastPathProcessor>(this);
                recastPathProcessor.MapId       = mapId;
                m_RecastPathProcessorDic[mapId] = recastPathProcessor;
                Log.Debug($"加载Id为{mapId}的地图Nav数据成功!");
            }
        }
コード例 #5
0
ファイル: RecastPathProcessor.cs プロジェクト: zhu64778065/ET
 public void CalculatePath(RecastPath recastPath)
 {
     if (RecastInterface.FindPath(this.MapId, recastPath.StartPos, recastPath.EndPos))
     {
         RecastInterface.Smooth(this.MapId, 2f, 0.5f);
         {
             int     smoothCount = 0;
             float[] smooths     = RecastInterface.GetPathSmooth(this.MapId, out smoothCount);
             for (int i = 0; i < smoothCount; ++i)
             {
                 Vector3 node = new Vector3(smooths[i * 3], smooths[i * 3 + 1], smooths[i * 3 + 2]);
                 recastPath.Results.Add(node);
             }
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// 卸载地图数据
        /// </summary>
        /// <param name="mapId">地图Id</param>
        public void UnLoadMapNavData(int mapId)
        {
            if (!m_RecastPathProcessorDic.ContainsKey(mapId))
            {
                Log.Warning($"不存在Id为{mapId}的地图Nav数据,无法进行卸载!");
                return;
            }

            m_RecastPathProcessorDic[mapId].Dispose();
            m_RecastPathProcessorDic.Remove(mapId);
            if (RecastInterface.FreeMap(mapId))
            {
                Log.Debug($"地图: {mapId}  释放成功");
            }
            else
            {
                Log.Debug($"地图: {mapId}  释放失败");
            }
        }