private int GetTileSelectedIndex(int i, int j) { char selected = selectedLevel.GetLevelData()[(j * selectedLevel.numColumns) + i]; int returnIdx = 0; switch (selected) { case ' ': returnIdx = 0; break; case '#': returnIdx = 1; break; case 'x': returnIdx = 2; break; default: break; } return(returnIdx); }
void GenerateRoomFromFile(string path) { Room room = Instantiate <GameObject>(RoomPrefab).GetComponent <Room>(); room.transform.parent = this.transform; BaseLevelObject Level = UnityEditor.AssetDatabase.LoadMainAssetAtPath(path) as BaseLevelObject; char[] currentLevelData = Level.GetLevelData(); int rowCount = Level.numRows; RoomStartPos = new Vector2(0, CellHeight * rowCount); room.RoomPosition = new Vector2(RoomStartPos.x, RoomStartPos.y); for (int i = 0; i < currentLevelData.Length; i++) { int x = i / rowCount; int y = i % rowCount; char currentChar = currentLevelData[i]; if (TileMappings.ContainsKey(currentChar)) { room.SetRoomSprite(x, y, TileMappings[currentChar]); } } GameObject player = Instantiate <GameObject>(PlayerPrefab); player.transform.position = new Vector3(CellWidth * 2, CellHeight * 2, 0); }