public void ToNextLevel() { _screenIsOpen = false; // pick a random level from the list of playable levels if (GameManager.Instance.PlayableLevelNames.Count == 0) // there are no levels left to choose from, reload all random levels. { Logger.Warning("We played all playable levels. Starting the random selection from the beginning"); GameManager.Instance.PlayableLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); } Logger.Log("number of found levels: " + GameManager.Instance.PlayableLevelNames.Count); int randomIndex = Random.Range(0, GameManager.Instance.PlayableLevelNames.Count); string pickedLevel = GameManager.Instance.PlayableLevelNames[randomIndex]; Logger.Log($"Load next random level: {pickedLevel}"); MazeLevelGameplayManager.Instance.LoadNextLevel(pickedLevel); // triggers load next level event for both players }
public EditorOverworld(OverworldData overworldData) { GameManager.Instance.CurrentEditorLevel = this; Name = overworldData.Name; if (TilesContainer.Instance != null) { GameObject.Destroy(TilesContainer.Instance.gameObject); TilesContainer.Instance = null; } _overworldContainer = new GameObject(Name); _overworldContainer.transform.SetParent(GameManager.Instance.GridGO.transform); _overworldContainer.transform.position = new Vector3(0, 0, 0); _overworldContainer.AddComponent <TilesContainer>(); _overworldContainer.SetActive(true); BuildTiles(overworldData); MazeLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); }
public void Start() { switch (PersistentGameManager.CurrentSceneType) { case SceneType.Overworld: Logger.Log("instantiate overworld sprites, tiles and characters"); if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.OverworldName == "") { PersistentGameManager.SetOverworldName("overworld"); } string overworldName = PersistentGameManager.OverworldName; Logger.Log($"We will load the maze '{overworldName}'"); OverworldData startUpOverworldData = OverworldLoader.LoadOverworldData(overworldName); if (startUpOverworldData == null) { Logger.Error("Could not find the default overworld for startup"); } OverworldLoader.LoadOverworld(startUpOverworldData); if (OverworldGameplayManager.Instance.Overworld == null) { Logger.Log(Logger.Initialisation, "No overworld loaded on startup. Returning"); return; } } // We loaded a overworld scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.OverworldModificationPanel.GenerateTiles(); } break; case SceneType.Maze: // We loaded a maze scene through the game. Set up the maze level if (PersistentGameManager.SceneLoadOrigin == SceneLoadOrigin.Gameplay) { if (PersistentGameManager.CurrentSceneName == "") { PersistentGameManager.SetCurrentSceneName("default"); } string mazeName = PersistentGameManager.CurrentSceneName; PersistentGameManager.SetLastMazeLevelName(mazeName); Logger.Log($"We will load the maze '{mazeName}'"); MazeLevelData startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); if (startUpMazeLevelData == null) { Logger.Error($"Could not find the level {mazeName} for startup. Will load defult level instead."); mazeName = "default"; startUpMazeLevelData = MazeLevelLoader.LoadMazeLevelData(mazeName); } MazeLevelLoader.LoadMazeLevel(startUpMazeLevelData); if (CurrentGameLevel == null) { Logger.Log(Logger.Initialisation, "No level loaded on startup. Returning"); return; } if (CurrentGameLevel.PlayerCharacterSpawnpoints.Count == 0) { return; } PlayableLevelNames = MazeLevelLoader.GetAllPlayableLevelNames(); } // We loaded a maze scene through the editor. Set up an empty grid for in the editor else { Logger.Log("create empty grid"); EditorCanvasUI.Instance.MazeModificationPanel.GenerateTiles(); } break; default: Logger.Error($"Scenetype {PersistentGameManager.CurrentSceneType} is not implemented yet"); break; } }