| |
---|
| | //地面地砖在 Atlas 的位置 |
---|
| | private List<Vector2I> _floorAtlasCoords; |
---|
| | //生成导航的结果 |
---|
| | private GenerateNavigationResult _generateNavigationResult; |
---|
| | |
---|
| | private InfiniteGrid<bool> _tempAisleFloorGrid = new InfiniteGrid<bool>(); |
---|
| | |
---|
| | public DungeonTileMap(TileMap tileRoot) |
---|
| | { |
---|
| | _tileRoot = tileRoot; |
---|
| |
---|
| | var index = random.RandomWeight(weights); |
---|
| | preinstallInfo = roomInfo.RoomSplit.Preinstall[index]; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | var roomPreinstall = new RoomPreinstall(roomInfo, preinstallInfo); |
---|
| | roomInfo.RoomPreinstall = roomPreinstall; |
---|
| | //执行预处理操作 |
---|
| | roomPreinstall.Pretreatment(random); |
---|
| |
---|
| | if (!doorInfo.IsForward) |
---|
| | { |
---|
| | continue; |
---|
| | } |
---|
| | |
---|
| | //普通的直线连接 |
---|
| | var doorDir1 = doorInfo.Direction; |
---|
| | var doorDir2 = doorInfo.ConnectDoor.Direction; |
---|
| | if (!doorInfo.HasCross) |
---|
| |
---|
| | new Vector2(rect2.Size.X - 2, 1)); |
---|
| | break; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //先计算范围 |
---|
| | var x = int.MaxValue; |
---|
| | var y = int.MaxValue; |
---|
| | var x2 = int.MinValue; |
---|
| | var y2 = int.MinValue; |
---|
| | _tempAisleFloorGrid.ForEach((gx, gy, data) => |
---|
| | { |
---|
| | x = Mathf.Min(x, gx); |
---|
| | x2 = Mathf.Max(x2, gx); |
---|
| | y = Mathf.Min(y, gy); |
---|
| | y2 = Mathf.Max(y2, gy); |
---|
| | }); |
---|
| | //创建image, 这里留两个像素宽高用于描边 |
---|
| | var image = Image.Create(x2 - x + 3, y2 - y + 3, false, Image.Format.Rgba8); |
---|
| | //填充像素点 |
---|
| | _tempAisleFloorGrid.ForEach((gx, gy, data) => |
---|
| | { |
---|
| | var posX = gx - x + 1; |
---|
| | var posY = gy - y + 1; |
---|
| | image.SetPixel(posX, posY, new Color(0, 0, 0, 0.5882353F)); |
---|
| | }); |
---|
| | //创建texture |
---|
| | var imageTexture = ImageTexture.CreateFromImage(image); |
---|
| | doorInfo.AislePreviewTexture = imageTexture; |
---|
| | doorInfo.ConnectDoor.AislePreviewTexture = imageTexture; |
---|
| | |
---|
| | _tempAisleFloorGrid.Clear(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /// <summary> |
---|
| |
---|
| | for (int i = 0; i < size.X; i++) |
---|
| | { |
---|
| | for (int j = 0; j < size.Y; j++) |
---|
| | { |
---|
| | _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 0, info.AutoTileCoord); |
---|
| | var p = new Vector2I((int)pos.X + i, (int)pos.Y + j); |
---|
| | if (layer == GameConfig.AisleFloorMapLayer) |
---|
| | { |
---|
| | _tempAisleFloorGrid.Set(p, true); |
---|
| | } |
---|
| | _tileRoot.SetCell(layer, p, 0, info.AutoTileCoord); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| |
---|
| | for (int i = 0; i < size.X; i++) |
---|
| | { |
---|
| | for (int j = 0; j < size.Y; j++) |
---|
| | { |
---|
| | _tileRoot.SetCell(layer, new Vector2I((int)pos.X + i, (int)pos.Y + j), 0); |
---|
| | var p = new Vector2I((int)pos.X + i, (int)pos.Y + j); |
---|
| | if (layer == GameConfig.AisleFloorMapLayer) |
---|
| | { |
---|
| | _tempAisleFloorGrid.Remove(p.X, p.Y); |
---|
| | } |
---|
| | _tileRoot.SetCell(layer, p, 0); |
---|
| | } |
---|
| | } |
---|
| | } |
---|
| | |
---|
| |
---|
| | |