コード例 #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
        /// <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 = ReferencePool.Acquire <RecastPathProcessor>();
                recastPathProcessor.MapId       = mapId;
                m_RecastPathProcessorDic[mapId] = recastPathProcessor;
                Log.Warning($"加载Id为{mapId}的地图Nav数据成功!");
            }
        }
コード例 #4
0
 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);
                 //Log.Info($"路径点:{node}");
             }
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// 卸载地图数据
        /// </summary>
        /// <param name="mapId">地图Id</param>
        public void UnLoadMapNavData(int mapId)
        {
            if (!m_RecastPathProcessorDic.ContainsKey(mapId))
            {
                Log.Warning($"不存在Id为{mapId}的地图Nav数据,无法进行卸载!");
                return;
            }

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