/// <summary>Adds hazard to the given tile.</summary> /// <param name="tile">Tile that the hazard will be spawned at.</param> public void AddLevelHazard(EditorTile tile) { if (tile.IsOccuppied() && !tile.GridObject.IsUnit()) { ObjectType type = ((EditorLevelObject)tile.GridObject).Type; if (type == editorParams.obj) { return; } } if (tile.Type != TileType.UnbreakableWall) { //Grid has change and file is no longer consistant with grid if (currentGridFile != null) { currentGridFile = null; } int variant = 0; if (editorParams.objVariants.ContainsKey(editorParams.obj)) { variant = editorParams.objVariants[editorParams.obj].variant; } EditorLevelObject hazard = new EditorLevelObject(editorParams.obj, tile, variant); tile.AddGridObject(hazard); if (levelObjects == null) { levelObjects = new List <EditorLevelObject>(); } levelObjects.Add(hazard); } }
/// <summary>Adds character spawns to the grid (only used for loading grids).</summary> /// <param name="spawns">List of spawn info to be added to the grid.</param> private void AddSpawners(List <UnitInfo> spawns) { if (spawns != null && spawns.Count > 0) { enemySpawns = new List <EditorUnit>(); foreach (UnitInfo info in spawns) { if (!CheckTilePosition(info.GetPosition())) { continue; } Vector2Int position = info.GetPosition(); EditorTile tile = grid[position.x].Get(position.y); UnitType type = info.GetInfoType(); EditorUnit character = new EditorUnit(type, tile); tile.AddGridObject(character); if (type == UnitType.Player) { player = character; } else if (type == UnitType.DecoyBot) { decoyBotSpawns.Add(character); } else { enemySpawns.Add(character); } } } }
/// <summary>Adds level objects to the level (only used for loading grids).</summary> /// <param name="levelObjectInfo">List of hazard info to be added to the grid.</param> public void AddLevelObjects(List <LevelObjectInfo> levelObjectInfo) { if (levelObjectInfo != null && levelObjectInfo.Count > 0) { levelObjects = new List <EditorLevelObject>(); foreach (LevelObjectInfo info in levelObjectInfo) { if (!CheckTilePosition(info.GetPosition())) { continue; } Vector2Int position = info.GetPosition(); EditorTile tile = grid[position.x].Get(position.y); ObjectType type = info.GetInfoType(); EditorLevelObject hazard = new EditorLevelObject(type, tile, info.GetVariant()); tile.AddGridObject(hazard); levelObjects.Add(hazard); } } }
/// <summary>Adds character spawn to the given tile.</summary> /// <param name="tile">Tile that the character will be spawned at.</param> public void AddCharacterSpawn(EditorTile tile) { bool isWall = false; if (tile.IsOccuppied()) { if (tile.GridObject.IsUnit()) { UnitType type = ((EditorUnit)tile.GridObject).Type; if (type == editorParams.unit) { return; } } else { isWall = ((EditorLevelObject)tile.GridObject).Type == ObjectType.Wall; } } if (tile.Type != TileType.UnbreakableWall && !isWall) { //Grid has change and file is no longer consistant with grid if (currentGridFile != null) { currentGridFile = null; } EditorUnit character = new EditorUnit(editorParams.unit, tile); tile.AddGridObject(character); switch (editorParams.unit) { case UnitType.Player: { if (player != null) { player.Tile.RemoveGridObject(); } player = character; break; } case UnitType.DecoyBot: { if (decoyBotSpawns == null) { decoyBotSpawns = new List <EditorUnit>(); } decoyBotSpawns.Add(character); break; } default: { if (enemySpawns == null) { enemySpawns = new List <EditorUnit>(); } enemySpawns.Add(character); break; } } } }