public void UpdateFinalGrids() { this.finalGrids = grids.InitArrays(Height(), Width()); for (int i = 0; i < grids.Length; i++) { for (int j = 0; j < grids[0].Length; j++) { int gridType = grids[i][j]; int projectGridType = projectGrids[i][j]; if (projectGridType == 0) //没有project_grid_type,则用grid_type { finalGrids[i][j] = gridType; } else { int field = AStarUtil.GetField(gridType); //用grid_type的field int terrainType = AStarUtil.GetTerrainType(projectGridType) != 0 ? AStarUtil.GetTerrainType(projectGridType) : AStarUtil.GetTerrainType(gridType); //覆盖关系 int obstacleType = AStarUtil.GetObstacleType(projectGridType) != 0 ? AStarUtil.GetObstacleType(projectGridType) : AStarUtil.GetObstacleType(gridType); //覆盖关系 finalGrids[i][j] = AStarUtil.ToGridType(field, terrainType, obstacleType); } } } }
protected override float GetG(Vector2Int p1, Vector2Int p2) { int dx = Math.Abs(p1.x - p2.x); int dy = Math.Abs(p1.y - p2.y); var terrainType = AStarUtil.GetTerrainType(astarMapPath.GetFinalGrids()[p2.x][p2.y]); float cost = AStarConst.AStarTerrainType_Dict[terrainType].cost; if (dx == 0 || dy == 0) //非斜线方向 { return(cost); } else //斜线方向 { return(cost * 1.414f); } }
void DrawDataDict() { for (int gridY = _target.astarConfigData.minGridY; gridY <= _target.astarConfigData.maxGridY; gridY++) { for (int gridX = _target.astarConfigData.minGridX; gridX <= _target.astarConfigData.maxGridX; gridX++) { int value = _target.astarConfigData.GetDataValue(gridX, gridY); int obstacleType = AStarUtil.GetObstacleType(value); int terrainType = AStarUtil.GetTerrainType(value); //draw obstacleType if (this.isSeeObstacleType && obstacleType == AStarConst.Default_Obstacle_Type_Value) { AStarEditorUtil.DrawObstacleTypeRect(_target, gridX, gridY, obstacleType); } // draw terrainType if (this.isSeeTerrainType && obstacleType == AStarConst.Default_Terrain_Type_Value) { AStarEditorUtil.DrawdTerrainTypeRect(_target, gridX, gridY, terrainType); } } } }
void HandleEvent() { if (e.control && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 0) //press { if (!_target.astarConfigData.IsInRange(mouseGridX, mouseGridY) && !_target.astarConfigData.isEnableEditOutsideBounds) { return; } int orgValue = _target.astarConfigData.GetDataValue(mouseGridX, mouseGridY); int obstacleType = AStarUtil.GetObstacleType(orgValue); int terrainType = AStarUtil.GetTerrainType(orgValue); if (isSeeObstacleType) { obstacleType = this.selectedObstacleType.value; } if (isSeeTerrainType) { terrainType = this.selectedTerrainType.value; } int value = AStarUtil.ToGridType(0, terrainType, obstacleType); _brush.DoPaintPressed(mouseGridX, mouseGridY, value); } }
public static void Test_GetTerrainType() { LogCat.log(AStarUtil.GetTerrainType(24)); }