private void AddBackgroundSprites(SerialisableTile serialisableTile, InGameOverworldTile tile) { InGameOverworldTileBackgroundPlacer tileBackgroundPlacer = new InGameOverworldTileBackgroundPlacer(tile); foreach (SerialisableTileBackground serialisableTileBackground in serialisableTile.TileBackgrounds) { Type type = Type.GetType(serialisableTileBackground.BackgroundType); if (type.Equals(typeof(SerialisableTilePathBackground))) { SerialisableTilePathBackground serialisableTilePathBackground = (SerialisableTilePathBackground)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlacePath(new OverworldDefaultPathType(), new TileConnectionScoreInfo(serialisableTilePathBackground.TileConnectionScore)); } else if (type.Equals(typeof(SerialisableTileBaseWater))) { tileBackgroundPlacer.PlaceBackground <OverworldTileBaseWater>(); } else if (type.Equals(typeof(SerialisableTileBaseGround))) { SerialisableTileBaseGround serialisableTileBaseGround = (SerialisableTileBaseGround)JsonUtility.FromJson(serialisableTileBackground.SerialisedData, type); tileBackgroundPlacer.PlaceGround(new OverworldDefaultGroundType(), new TileConnectionScoreInfo(serialisableTileBaseGround.TileConnectionScore)); } else { Logger.Error($"Unknown background of type {type}"); } } }
private void InitialiseTileAttributes() { for (int i = 0; i < Overworld.Tiles.Count; i++) { InGameOverworldTile tile = Overworld.Tiles[i] as InGameOverworldTile; tile.InitialiseTileAttributes(); } }
public override void Start() { base.Start(); // transform the player's starting tile and surrounding tiles InGameOverworldTile currentTile = GameManager.Instance.CurrentGameLevel.TilesByLocation[StartingPosition] as InGameOverworldTile; SetCurrentGridLocation(currentTile.GridLocation); }
private void AddCornerFillers(SerialisableTile serialisableTile, InGameOverworldTile tile) { InGameOverworldTileBackgroundPlacer tileBackgroundPlacer = new InGameOverworldTileBackgroundPlacer(tile); // corner filler is also an IBackground foreach (SerialisableTileCornerFiller serialisableTileCornerFiller in serialisableTile.TileCornerFillers) { if (Enum.TryParse(serialisableTileCornerFiller.TileCorner, out TileCorner tileCorner)) { tileBackgroundPlacer.PlaceCornerFiler(tileCorner); } else { Logger.Error($"Could not parse the TileCorner value{serialisableTileCornerFiller.TileCorner}"); } } }
public void BuildTiles(OverworldData overworldData) { Dictionary <InGameOverworldTile, List <SerialisableGridLocation> > TileTransformationGridLocationByTile = new Dictionary <InGameOverworldTile, List <SerialisableGridLocation> >(); for (int i = 0; i < overworldData.Tiles.Count; i++) { SerialisableTile serialisableTile = overworldData.Tiles[i]; GameObject tileGO = GameObject.Instantiate(OverworldGameplayManager.Instance.InGameTilePrefab, _overworldContainer.transform); InGameOverworldTile tile = tileGO.GetComponent <InGameOverworldTile>(); tile.SetGridLocation(serialisableTile.GridLocation.X, serialisableTile.GridLocation.Y); tile.SetId(serialisableTile.Id); tileGO.name = "Tile" + tile.GridLocation.X + ", " + tile.GridLocation.Y; tileGO.transform.position = GridLocation.GridToVector(tile.GridLocation); Tiles.Add(tile); AddBackgroundSprites(serialisableTile, tile); AddTileAttributes(serialisableTile, tile); AddCornerFillers(serialisableTile, tile); TilesByLocation.Add(tile.GridLocation, tile); GridLocation furthestBounds = LevelBounds; if (tile.GridLocation.X > furthestBounds.X) { _levelBounds.X = tile.GridLocation.X; } if (tile.GridLocation.Y > furthestBounds.Y) { _levelBounds.Y = tile.GridLocation.Y; } TileTransformationGridLocationByTile.Add(tile, serialisableTile.TilesToTransform); } for (int k = 0; k < Tiles.Count; k++) { InGameOverworldTile tile = Tiles[k] as InGameOverworldTile; tile.AddNeighbours(this); } }
private void AddTileAttributes(SerialisableTile serialisableTile, InGameOverworldTile tile) { InGameOverworldTileAttributePlacer tileAttributePlacer = new InGameOverworldTileAttributePlacer(tile); foreach (SerialisableTileAttribute serialisableTileAttribute in serialisableTile.TileAttributes) { Type type = Type.GetType(serialisableTileAttribute.AttributeType); if (type.Equals(typeof(SerialisableMazeLevelEntryAttribute))) { SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = (SerialisableMazeLevelEntryAttribute)JsonUtility.FromJson(serialisableTileAttribute.SerialisedData, type); MazeLevelEntry mazeLevelEntry = tileAttributePlacer.PlaceMazeLevelEntry(serialisableMazeLevelEntryAttribute.MazeLevelName); MazeEntries.Add(mazeLevelEntry); } else if (type.Equals(typeof(SerialisablePlayerSpawnpointAttribute))) { tileAttributePlacer.PlacePlayerSpawnpoint(); } else { Logger.Error($"Unknown tile attribute of type {type}"); } } }