コード例 #1
0
        private void LoadDatasFromBin()
        {
            string binPath = Path.Combine(this.binBasePath, this.navMeshName.Trim());

            if (File.Exists(binPath + ".bin"))
            {
                TileCacheRecast recast = new TileCacheRecast();
                recast.LoadMeshBin(binPath);
                //加载配置数据
                this.LoadBuildSettings(recast);
                //加载顶点区域数据
                this.LoadConvexDatasFromBin(recast);

                recast.Release();
            }
            else
            {
                Debug.LogWarning($"Can't load bin file by " + binPath);
            }
        }
コード例 #2
0
        private void BuildBinary(string objPath, string binPath, List <ConvexVolume> convexVolumes)
        {
            TileCacheRecast recast = new TileCacheRecast();

            //Set Building Params
            recast.SetBuildingParams(this.settings.agentHeight, this.settings.agentRadius,
                                     this.settings.agentMaxClimb, this.settings.agentMaxSlope,
                                     this.settings.cellSize, this.settings.cellHeight, this.settings.regionMinSize,
                                     this.settings.regionMergeSize, this.settings.edgeMaxLen, this.settings.edgeMaxError,
                                     this.settings.vertsPerPoly, this.settings.detailSampleDist, this.settings.detailSampleMaxError,
                                     this.settings.partitionType, this.settings.tileSize);

            if (recast.LoadGeometry(objPath))
            {
                //添加特殊多边形区域
                foreach (var data in convexVolumes)
                {
                    if (data.Verts.Count > 2)
                    {
                        //顶点数必须大于两个
                        foreach (var p in data.Verts)
                        {
                            recast.AddConvexPoint(p);
                        }
                        if (recast.MakeConvexPolygon(data.AreaType))
                        {
                            Debug.Log($"{data.AreaType.ToString()}: 添加成功");
                        }
                    }
                }

                recast.Build(binPath);
                Debug.Log("Nav Bin File Build Success!");
                Debug.Log(binPath);
            }
            else
            {
                Debug.LogError("Parse Obj File Failed at " + objPath);
            }
            recast.Release();
        }