public void GenerateObstacleInfo(CellManager cellMgr) { //标记所有格子为阻挡 for (int row = 0; row < cellMgr.GetMaxRow(); row++) { for (int col = 0; col < cellMgr.GetMaxCol(); col++) { cellMgr.SetCellStatus(row, col, BlockType.STATIC_BLOCK); } } //打开可行走区 foreach (TiledData data in walk_area_list_) { List <Vector3> pts = data.GetPoints(); MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.NOT_BLOCK); } //标记阻挡区 foreach (TiledData data in obstacle_area_list_) { List <Vector3> pts = data.GetPoints(); MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.STATIC_BLOCK); } //标记阻挡线 foreach (TiledData data in obstacle_line_list_) { List <Vector3> pts = data.GetPoints(); MarkObstacleLine(pts, cellMgr, BlockType.STATIC_BLOCK); } }
public void Init(CellManager cellMgr) { m_CellMgr = cellMgr; m_Map = cellMgr.cells_arr_; m_MaxRows = cellMgr.GetMaxRow(); m_MaxCols = cellMgr.GetMaxCol(); m_PreprocessData = null; }
public void PreprocessMap(CellManager cellMgr, string filename) { m_Width = cellMgr.GetMaxCol(); m_Height = cellMgr.GetMaxRow(); byte[,] map = cellMgr.cells_arr_; using (FileStream fs = new FileStream(filename, FileMode.Create)) { // init fs.WriteByte((byte)(m_Width & 0x0ff)); fs.WriteByte((byte)((m_Width & 0x0ff00) >> 8)); fs.WriteByte((byte)(m_Height & 0x0ff)); fs.WriteByte((byte)((m_Height & 0x0ff00) >> 8)); int size = map.Length; m_Tree = new TreeNode[size]; m_PreTree = new PreTreeNode[size]; for (int i = 0; i < size; ++i) { m_PreTree[i].Wall = BlockType.GetBlockType(map[i / m_Width, i % m_Width]) == 0; m_Tree[i].OpToParent = (byte)OperationEnum.NO_OP; m_PreTree[i].Visited = false; m_PreTree[i].CostF = float.MaxValue; m_Tree[i].CostI = (byte)255; } // Create Trees (multiple roots are possible) for (int i = 0; i < size; ++i) { if (m_PreTree[i].Wall && !m_PreTree[i].Visited) { CreateTree(i); } } // Compact for (int i = 0; i < size; ++i) { // Round up to ensure that only the root node gets a cost of 0. double scaledCostF = Math.Min(254.0, Math.Ceiling(m_PreTree[i].CostF / 5.0)); int scaledCostI = (int)scaledCostF; m_Tree[i].CostI = (byte)scaledCostI; } for (int i = 0; i < size; ++i) { fs.WriteByte(m_Tree[i].CostI); fs.WriteByte(m_Tree[i].OpToParent); } fs.Close(); } m_PreTree = null; m_Tree = null; }
public void GenerateObstacleInfoWithNavmesh(CellManager cellMgr) { //标记所有格子为阻挡 for (int row = 0; row < cellMgr.GetMaxRow(); row++) { for (int col = 0; col < cellMgr.GetMaxCol(); col++) { cellMgr.SetCellStatus(row, col, BlockType.STATIC_BLOCK); } } //打开可行走区 foreach (TriangleNode node in navmesh_triangle_list) { List <Vector3> pts = new List <Vector3>(node.Points); MapDataUtil.MarkObstacleArea(pts, cellMgr, BlockType.NOT_BLOCK); } }