コード例 #1
0
        public NavMeshInfo Load(string path)
        {
            List <string> fileInfo    = LoadFile(path);
            NavMeshInfo   navMeshInfo = ReadInfo(fileInfo);

            return(navMeshInfo);
        }
コード例 #2
0
        /// <summary>
        /// 读取数据
        /// </summary>
        /// <param name="fileInfo">文件信息</param>
        /// <returns></returns>
        NavMeshInfo ReadInfo(List <string> fileInfo)
        {
            NavMeshInfo navMeshInfo = new NavMeshInfo();

            for (int i = 0; i < fileInfo.Count; i++)
            {
                string str = fileInfo[i];

                string[] Split = str.Split(' ');

                if (Split[0] == "v")
                {
                    allPoint.Add(new Vector3(float.Parse(Split[1]), float.Parse(Split[2]), float.Parse(Split[3])));
                }
                else if (Split[0] == "f")
                {
                    int indicesA = int.Parse(Split[1]);
                    int indicesB = int.Parse(Split[2]);
                    int indicesC = int.Parse(Split[3]);

                    Vector3 a = allPoint[indicesA - 1];
                    Vector3 b = allPoint[indicesB - 1];
                    Vector3 c = allPoint[indicesC - 1];

                    AStarPoint aStarPointA = new AStarPoint(a);
                    AStarPoint aStarPointB = new AStarPoint(b);
                    AStarPoint aStarPointC = new AStarPoint(c);

                    AStarTriangle triangle = new AStarTriangle(aStarPointA, aStarPointB, aStarPointC);

                    navMeshInfo.allCentroid.Add(triangle.centroid);

                    AddPointIndices(navMeshInfo.pointIndexes, aStarPointA, triangle);
                    AddPointIndices(navMeshInfo.pointIndexes, aStarPointB, triangle);
                    AddPointIndices(navMeshInfo.pointIndexes, aStarPointC, triangle);
                }
            }
            return(navMeshInfo);
        }