/// <summary> /// Starts a mini game sequence. /// </summary> private void StartMiniGameSequence() { if (m_state != State.METAGAME && m_state != State.RESULTS) { // Don't let this spam! return; } // Reset variables m_currentMiniGameScene = SceneInfo.SceneEnum.SIZE; m_currentLives = m_maxLives; m_currentScore = 0; m_currentLevel = 0; m_miniGameCountThisLevel = 0; // Prepare the UI Main.Instance.GetScoreUI.Reset(); Main.Instance.GetFasterUI.Reset(); // Play the MiniGame BGM Locator.GetSoundManager().PlayMiniGameBGM(); Locator.GetSoundManager().AdjustMiniGameBGMPitch(m_currentLevel); // Create a set of minigames CreateMiniGameSet(); // Get a new random minigame LoadNextMiniGame(); }
/// <summary> /// Goes to next mini game. /// </summary> private void LoadNextMiniGame() { // Load the next mini game m_currentMiniGameScene = m_miniGameSet[GetNextMiniGameSetIndex()]; // For testing: Uncomment and replace to have GameManager load only the specified MiniGame //m_currentMiniGameScene = SceneInfo.SceneEnum.MINIGAME_PLANE; m_state = State.MINIGAME_LOADING; Main.Instance.NotifySwitchScene(m_currentMiniGameScene); }
/// <summary> /// Notifies Main of request to load the specified scene. /// </summary> /// <returns><c>true</c>, if scene switch request is granted, <c>false</c> otherwise.</returns> /// <param name="nextScene">Scene to switch to.</param> /// <param name="fadeOut">Whether scene should fade out before switching to the next scene</param> public bool NotifySwitchScene(SceneInfo.SceneEnum nextScene, bool fadeOut = true) { if (nextScene == SceneInfo.SceneEnum.SIZE) { Debug.LogWarning("Specified item is not a scene"); return(false); } // If already loading a new scene, do not load another scene if (m_curScene != m_nextScene) { return(false); } m_nextScene = nextScene; m_enableFadeAnim = fadeOut; // Start scene loading m_initState = InitState.LOAD_SCENE; return(true); }
/// <summary> /// Creates the mini game set. /// </summary> private void CreateMiniGameSet() { int actualSetCount = m_miniGameCountPerSet; if (m_miniGameCountPerSet <= 0) { actualSetCount = (int)LastMiniGameScene - (int)FirstMiniGameScene + 1; } m_miniGameSet.Clear(); m_miniGameSet.Capacity = actualSetCount; // Fill up the set with random mini games for (uint i = 0; i < actualSetCount; ++i) { SceneInfo.SceneEnum mgEnum = FirstMiniGameScene; do { mgEnum = GetRandomMiniGameScene(); }while (m_miniGameSet.Contains(mgEnum)); m_miniGameSet.Add(mgEnum); } }
/// <summary> /// Awake this instance. /// </summary> private void Awake() { // Initialize the service locator Locator.Initialize(); if (Locator.GetMain() == null) { // Provide this instance of Main to the service locator Locator.ProvideMain(this); // Main is always present in the game DontDestroyOnLoad(this.gameObject); // Mark this as the only instance of Main allowed in the game m_isActiveMain = true; // Check if game started from the Main scene int loadedLevel = Application.loadedLevel; if (loadedLevel == 0) { m_isGameStartedFromMain = true; } // If not started from Main, initialize scene enum values to the current scene else { // Scene enums are just the scene index minus one SceneInfo.SceneEnum curScene = (SceneInfo.SceneEnum)loadedLevel - 1; m_prevScene = curScene; m_curScene = curScene; } } else { // Pass the reference to this scene's SceneMaster to the existing Main instance Locator.GetMain().SetSceneMaster(m_sceneMaster); // There can be only one instance of Main in the game Destroy(this.gameObject); } }