private string GenerateAssignedAreasText(EnemySpawnpoint enemySpawnpoint) { string assignedAreaString = "Assigned areas:\n"; for (int j = 0; j < enemySpawnpoint.TileAreas.Count; j++) { assignedAreaString += $"{enemySpawnpoint.TileAreas[j].Name}\n"; } return(assignedAreaString); }
public void RemoveEnemySpawnpoint(EnemySpawnpoint enemySpawnpoint = null) { if (enemySpawnpoint == null) { enemySpawnpoint = (EnemySpawnpoint)_tile.GetAttributes().FirstOrDefault(attribute => attribute is EnemySpawnpoint); } if (enemySpawnpoint == null) { return; } _tile.RemoveAttribute(enemySpawnpoint); MazeLevelGameplayManager.Instance.EnemyCharacterSpawnpoints.Remove(enemySpawnpoint); enemySpawnpoint.Remove(); }
// Every time we access a different tile, check if there is an enemy spawnpoint on it public void CheckForEnemySpawnpointOnTile() { MazeTile selectedTile = EditorTileSelector.Instance.CurrentlySelectedTile as MazeTile; EnemySpawnpoint enemySpawnpoint = selectedTile?.TryGetEnemySpawnpoint(); if (enemySpawnpoint == null) { _tileAreaNamesDropdown.gameObject.SetActive(false); _assignedAreasText.gameObject.SetActive(false); } else { _tileAreaNamesDropdown.gameObject.SetActive(true); _assignedAreasText.gameObject.SetActive(true); RedrawAssignedAreasTest(enemySpawnpoint); RedrawDropdownOptions(); } }
public void Delete() { TileAreaActionHandler.Instance.DeselectTileAreaEntry(this); TileAreaActionHandler.Instance.TileAreaEntries.Remove(this); GameManager.Instance.CurrentEditorLevel.TileAreas.Remove(TileArea.Id); //Delete this tile area from any existing enemy spawnpoints for (int i = 0; i < MazeLevelGameplayManager.Instance.EnemyCharacterSpawnpoints.Count; i++) { Logger.Warning("remove tile area"); EnemySpawnpoint enemySpawnpoint = MazeLevelGameplayManager.Instance.EnemyCharacterSpawnpoints[i]; enemySpawnpoint.RemoveTileArea(TileArea); } GameObject.Destroy(gameObject); GameObject.Destroy(this); }
public virtual void PlaceEnemySpawnpoint(List <string> tileAreaIds = null, Dictionary <string, TileArea> globalTileAreas = null) { EnemySpawnpoint enemySpawnpoint = (EnemySpawnpoint)InstantiateTileAttributeGO <EnemySpawnpoint>(); Tile.SetWalkable(true); Tile.TryMakeMarkable(true); Tile.AddAttribute(enemySpawnpoint); MazeLevelGameplayManager.Instance.EnemyCharacterSpawnpoints.Add(enemySpawnpoint); if (tileAreaIds != null && globalTileAreas != null) { for (int i = 0; i < tileAreaIds.Count; i++) { TileArea tileArea = globalTileAreas[tileAreaIds[i]]; enemySpawnpoint.AddTileArea(tileArea); } } }
private void RedrawDropdownOptions() { MazeTile selectedTile = EditorTileSelector.Instance.CurrentlySelectedTile as MazeTile; EnemySpawnpoint enemySpawnpoint = selectedTile?.TryGetEnemySpawnpoint(); for (int i = 1; i < _tileAreaNamesDropdown.options.Count; i++) { string areaId = _tileAreaIdByDropdownOption[_tileAreaNamesDropdown.options[i]]; TileArea tileArea = GameManager.Instance.CurrentEditorLevel.TileAreas[areaId]; string originalAreaName = tileArea.Name; if (enemySpawnpoint.TileAreas.Contains(tileArea)) { _tileAreaNamesDropdown.options[i].text = $"(X) {originalAreaName}"; } else { _tileAreaNamesDropdown.options[i].text = originalAreaName; } } }
private void AddTileAreaToSpawnpoint() { if (_tileAreaNamesDropdown.value == 0) { return; } MazeTile selectedTile = EditorTileSelector.Instance.CurrentlySelectedTile as MazeTile; EnemySpawnpoint enemySpawnpoint = selectedTile?.TryGetEnemySpawnpoint(); if (enemySpawnpoint == null) { Logger.Log("could not find enemySpawnpoint on the selected tile"); return; } string currentlySelectedTileAreaId = GetIdCurrentSelectedTileArea(); TileArea tileAreaInList = enemySpawnpoint.TileAreas.FirstOrDefault(tileArea => tileArea.Id == currentlySelectedTileAreaId); TileArea tileArea = GameManager.Instance.CurrentEditorLevel.TileAreas[currentlySelectedTileAreaId]; if (tileAreaInList == null) { Logger.Log("did not find the area in the list, so we add it"); enemySpawnpoint.AddTileArea(tileArea); } else { Logger.Log($"The currently selected tile area is {tileAreaInList.Name}"); enemySpawnpoint.RemoveTileArea(tileArea); } _assignedAreasText.text = GenerateAssignedAreasText(enemySpawnpoint); RedrawDropdownOptions(); _tileAreaNamesDropdown.value = 0; }
public EnemySpawnpoint TryGetEnemySpawnpoint() { EnemySpawnpoint enemySpawnpoint = (EnemySpawnpoint)_tileAttributes.FirstOrDefault(attribute => attribute is EnemySpawnpoint); return(enemySpawnpoint); }
private void RedrawAssignedAreasTest(EnemySpawnpoint enemySpawnpoint) { _assignedAreasText.text = GenerateAssignedAreasText(enemySpawnpoint); }
private ISerialisableTileAttribute CreateSerialisableTileAttribute(Tile tile, ITileAttribute tileAttribute) { if (tileAttribute.GetType() == typeof(TileObstacle)) { TileObstacle tileObstacle = tileAttribute as TileObstacle; SerialisableTileObstacleAttribute serialisableTileObstacleAttribute = new SerialisableTileObstacleAttribute( new TileConnectionScoreInfo(tileObstacle.ConnectionScore, tileObstacle.SpriteNumber)); return(serialisableTileObstacleAttribute); } else if (tileAttribute.GetType() == typeof(PlayerExit)) { PlayerExit playerExit = tileAttribute as PlayerExit; SerialisablePlayerExitAttribute serialisablePlayerExitAttribute = new SerialisablePlayerExitAttribute( new TileConnectionScoreInfo(playerExit.ConnectionScore, playerExit.SpriteNumber)); return(serialisablePlayerExitAttribute); } else if (tileAttribute.GetType() == typeof(PlayerOnly)) { SerialisablePlayerOnlyAttribute serialisablePlayerOnlyAttribute = new SerialisablePlayerOnlyAttribute(); return(serialisablePlayerOnlyAttribute); } else if (tileAttribute.GetType() == typeof(PlayerSpawnpoint)) { SerialisablePlayerSpawnpointAttribute serialisablePlayerSpawnpointAttribute = new SerialisablePlayerSpawnpointAttribute(); return(serialisablePlayerSpawnpointAttribute); } else if (tileAttribute.GetType() == typeof(EnemySpawnpoint)) { EnemySpawnpoint enemySpawnpoint = tileAttribute as EnemySpawnpoint; SerialisableEnemySpawnpointAttribute serialisableEnemySpawnpointAttribute = new SerialisableEnemySpawnpointAttribute(enemySpawnpoint.TileAreas); return(serialisableEnemySpawnpointAttribute); } else if (tileAttribute.GetType() == typeof(MazeLevelEntry)) { MazeLevelEntry mazeLevelEntry = tileAttribute as MazeLevelEntry; SerialisableMazeLevelEntryAttribute serialisableMazeLevelEntryAttribute = new SerialisableMazeLevelEntryAttribute(mazeLevelEntry.MazeLevelName); return(serialisableMazeLevelEntryAttribute); } else if (tileAttribute.GetType() == typeof(BridgePiece)) { BridgePiece bridgePiece = tileAttribute as BridgePiece; BridgePieceDirection bridgePieceDirection = bridgePiece.BridgePieceDirection; SerialisableBridgePieceAttribute serialisableBridgePieceAttribute = new SerialisableBridgePieceAttribute(bridgePieceDirection); return(serialisableBridgePieceAttribute); } else if (tileAttribute.GetType() == typeof(BridgeEdge)) { BridgeEdge bridgeEdge = tileAttribute as BridgeEdge; SerialisableBridgeEdgeAttribute serialisableBridgeEdgeAttribute = new SerialisableBridgeEdgeAttribute(bridgeEdge.EdgeSide); return(serialisableBridgeEdgeAttribute); } else if (tileAttribute.GetType() == typeof(MusicInstrumentCase)) { SerialisableMusicInstrumentCaseAttribute serialisableMusicInstrumentCaseAttribute = new SerialisableMusicInstrumentCaseAttribute(); return(serialisableMusicInstrumentCaseAttribute); } else { Logger.Error($"Could not serialise the tile attribute {tileAttribute.GetType()}"); return(null); } }