public static void LoadLevel <TMap, TCodes>(string levelName) where TMap : IMap <TCodes>, new() { var tileMap = TileMap <TMap, TCodes> .GetInstance(); CurrentLevel = levelName; tileMap.LoadMap(new FileStream($"{AppDomain.CurrentDomain.BaseDirectory}/Content/maps/{levelName}.map", FileMode.Open)); Camera.UpdateWorldRectangle(tileMap); OnLevelLoad?.Invoke(); }
void GenerateLevel() { Texture2D level; if (SceneManager.GetActiveScene().name == "IterateLevel") { level = levels[Random.Range(0, levels.Length)]; } else { level = levels[0]; } mainCam = Camera.main; mainCam.orthographicSize = (level.height / 2) + 1; mainCam.transform.position = new Vector3(level.width * 0.5f, (level.height * 0.5f) - 0.5f, -10); for (int x = 0; x < level.width; x++) { for (int y = 0; y < level.height; y++) { Color pixelColor = level.GetPixel(x, y); if (pixelColor == Color.black) { Instantiate(wallObj, new Vector2(x, y), Quaternion.identity); } else if (pixelColor == Color.white) { Instantiate(smallPelletObj, new Vector2(x, y), Quaternion.identity); spawnedPellets++; } else if (pixelColor == Color.green) { int randomPowerup = Random.Range(0, spawnablePowerups.Length); Instantiate(spawnablePowerups[randomPowerup], new Vector2(x, y), Quaternion.identity); } else { for (int i = 0; i < ColorsToSpawn.Length; i++) { if (pixelColor == ColorsToSpawn[i].Color) { Instantiate(ColorsToSpawn[i].GameObject, new Vector2(x, y), Quaternion.identity); } } } } } OnLevelLoad?.Invoke(); AStarGrid.Instance.CreateGrid(); }
private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1) { if (arg0.name == MainMenuScene && _returnToLevelSelect) { _returnToLevelSelect = false; // TODO: Show level select. } Debug.Log("Level Loaded"); _activeLevel = _levels.Find(l => l.SceneName == SceneManager.GetActiveScene().name); if (_activeLevel != null) { OnLevelLoad?.Invoke(_activeLevel); } }