private void UpdateNeighboursForRemovedObstacle(ObstacleType obstacleType) { foreach (KeyValuePair <ObjectDirection, Tile> neighbour in _tile.Neighbours) { if (!neighbour.Value) { continue; } TileObstacle tileObstacleOnNeighbour = neighbour.Value.TryGetTileObstacle(); if (tileObstacleOnNeighbour == null) { continue; } Logger.Log($"We will look for connections for neighbour {neighbour.Value.GridLocation.X},{neighbour.Value.GridLocation.Y}, which is {neighbour.Key} of {_tile.GridLocation.X},{_tile.GridLocation.Y}"); TileConnectionScoreInfo obstacleConnectionScoreOnNeighbour = NeighbourTileCalculator.MapNeighbourObstaclesOfTile(neighbour.Value, obstacleType); Logger.Log($"We calculated an obstacle connection type score of {obstacleConnectionScoreOnNeighbour.RawConnectionScore} for location {neighbour.Value.GridLocation.X}, {neighbour.Value.GridLocation.Y}"); //update connection score on neighbour tileObstacleOnNeighbour.WithConnectionScoreInfo(obstacleConnectionScoreOnNeighbour); // If needed, place a background if (obstacleConnectionScoreOnNeighbour.RawConnectionScore != NeighbourTileCalculator.ConnectionOnAllSidesScore) { MazeTileBaseGround oldMazeTileBaseGround = (MazeTileBaseGround)neighbour.Value.GetBackgrounds().FirstOrDefault(background => background is MazeTileBaseGround); if (oldMazeTileBaseGround == null) { EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(neighbour.Value as EditorMazeTile); tileBackgroundPlacer.PlaceBackground <MazeTileBaseGround>(); } } } }
public override void PlaceGround(IBaseBackgroundType groundType, TileConnectionScoreInfo connectionScoreInfo) { GameObject groundGO = GameObject.Instantiate(MazeLevelGameplayManager.Instance.GetTileBackgroundPrefab <MazeTileBaseGround>(), Tile.BackgroundsContainer); MazeTileBaseGround mazeTileBaseGround = groundGO.GetComponent <MazeTileBaseGround>(); mazeTileBaseGround.WithType(groundType); mazeTileBaseGround.WithConnectionScoreInfo(connectionScoreInfo); mazeTileBaseGround.SetTile(Tile); Tile.AddBackground(mazeTileBaseGround); }
public override void PlaceBackground(EditorMazeTile tile) { EditorMazeTileBackgroundPlacer tileBackgroundPlacer = new EditorMazeTileBackgroundPlacer(tile); MazeTileBackgroundRemover tileBackgroundRemover = new MazeTileBackgroundRemover(tile); MazeTileAttributeRemover tileAttributeRemover = new MazeTileAttributeRemover(tile); Type oldMainMaterial = tile.TileMainMaterial?.GetType(); // old material before updating it MazeTileBaseGround oldMazeTileBaseGround = (MazeTileBaseGround)tile.GetBackgrounds().FirstOrDefault(background => background is MazeTileBaseGround); if ((oldMainMaterial != typeof(GroundMainMaterial))) { List <ITileAttribute> attributes = tile.GetAttributes(); for (int i = 0; i < attributes.Count; i++) { tileAttributeRemover.Remove(attributes[i]); } // Remove the old land background, because we are going to fully cover it with a new land background if (oldMazeTileBaseGround != null && oldMazeTileBaseGround.ConnectionScore != 16) { tileBackgroundRemover.RemoveBackground <MazeTileBaseGround>(); } MazeTileBaseGround newMazeTileBaseGround = tileBackgroundPlacer.PlaceBackground <MazeTileBaseGround>(); // Remove water from the tile that is fully covered by land if (newMazeTileBaseGround.ConnectionScore == 16) { tileBackgroundRemover.RemoveBackground <MazeTileBaseWater>(); } } // Place corner fillers TileCornerFillerRegister.TryPlaceCornerFillers(tile); TileCornerFillerRegister.TryPlaceCornerFillersForNeighbours(tile); }