public override void OnAddToLevel(LevelGrid grid, GridCoord position) { // Try to link to an unused toggle. ToggleTriggerPlatformSquare toggle = FindUnusedToggleTriggerPlatformSquare(grid); if (toggle != null) { toggleSquare = toggle; toggleSquare.triggerSquare = this; } }
public LevelDefinition AsLevelDefinition() { LevelDefinition level = new LevelDefinition(); string[][] levelData = new string[m_grid.GetLength(1)][]; for (int y = 0; y < m_grid.GetLength(1); ++y) { levelData[y] = new string[m_grid.GetLength(0)]; } int triggerID = 1; int warpID = 1; for (int y = 0; y < m_grid.GetLength(1); ++y) { for (int x = 0; x < m_grid.GetLength(0); ++x) { if (m_grid[x, y] == null) { Debug.LogWarning(string.Format("Warning: Trying to write null grid square at ({1}, {2})", x, y)); continue; } levelData [y] [x] = m_grid [x, y].GetPlatformTypeString(); // Custom grid processing. // @TODO Relocate this into a per-PlatformSquare "GetAttributeString()" method. if (m_grid[x, y] is ToggleTriggerPlatformSquare) { if (string.IsNullOrEmpty(levelData[y][x])) { string triggerAttributes = "id=" + triggerID + ",oneway=" + ((m_grid [x, y] as ToggleTriggerPlatformSquare).oneWayToggle ? "y" : "n"); string triggerString = "T[" + triggerAttributes + "]"; levelData [y] [x] = triggerString; ToggleTriggerPlatformSquare toggleSquare = m_grid [x, y] as ToggleTriggerPlatformSquare; if (toggleSquare.triggerSquare != null && string.IsNullOrEmpty(levelData [toggleSquare.triggerSquare.GridPosition.y] [toggleSquare.triggerSquare.GridPosition.x])) { string toggleString = "t[id=" + triggerID + "]"; levelData [toggleSquare.triggerSquare.GridPosition.y] [toggleSquare.triggerSquare.GridPosition.x] = toggleString; } triggerID++; } } else if (m_grid[x, y] is TriggeredPlatformSquare) { if (string.IsNullOrEmpty(levelData[y][x])) { string toggleString = "t[id=" + triggerID + "]"; levelData [y] [x] = toggleString; TriggeredPlatformSquare square = m_grid [x, y] as TriggeredPlatformSquare; if (square.toggleSquare != null && string.IsNullOrEmpty(levelData [square.toggleSquare.GridPosition.y] [square.toggleSquare.GridPosition.x])) { string triggerAttributes = "id=" + triggerID + ",oneway=" + ((m_grid [square.toggleSquare.GridPosition.x, square.toggleSquare.GridPosition.y] as ToggleTriggerPlatformSquare).oneWayToggle ? "y" : "n"); string triggerString = "T[" + triggerAttributes + "]"; levelData [square.toggleSquare.GridPosition.y] [square.toggleSquare.GridPosition.x] = triggerString; } triggerID++; } } else if (m_grid[x, y] is WarpSquare) { if (string.IsNullOrEmpty(levelData[y][x])) { string attributes = "id=" + warpID; string warpString = "W[" + attributes + "]"; levelData[y][x] = warpString; WarpSquare warpSquare = m_grid[x, y] as WarpSquare; if (warpSquare.destination != null && string.IsNullOrEmpty(levelData[warpSquare.destination.GridPosition.y][warpSquare.destination.GridPosition.x])) { string destinationString = "w[id=" + warpID + "]"; levelData[warpSquare.destination.GridPosition.y][warpSquare.destination.GridPosition.x] = destinationString; } warpID++; } } } } level.levelGrid = levelData; return(level); }