// ----------------------------------------------------------------------------------- IEnumerator ShowCoroutine(CharacterFile.File characterFile, int round) { // deselect everything while showing the image GameObject prevSelection = EventSystem.current.currentSelectedGameObject; EventSystem.current.SetSelectedGameObject(null); RawImage target = characterFile.IsPortrait(round) ? portrait : landscape; // transition to black, load the images yield return(StartCoroutine(Transition.instance.Show())); CharacterFile.RoundImages images = characterFile.LoadRound(round); target.texture = images.baseImage; target.enabled = true; artist.text = "ARTIST:" + characterFile.artist.ToUpper(); localBackground.SetActive(true); yield return(StartCoroutine(Transition.instance.Hide())); // wait yield return(null); while (!Input.GetButtonDown("Cut")) { yield return(null); } // show stats SoundManager.instance.PlaySFX("ui_sweep_in"); stats.Show(round, characterFile.guid); // wait yield return(null); while (!Input.GetButtonDown("Cut")) { yield return(null); } // transition out, hide the stats and images yield return(StartCoroutine(Transition.instance.Show())); stats.Hide(); localBackground.SetActive(false); artist.text = ""; target.enabled = false; yield return(StartCoroutine(Transition.instance.Hide())); // disable the game object gameObject.SetActive(false); // restore selection EventSystem.current.SetSelectedGameObject(prevSelection); }
// --- Methods ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------- IEnumerator InitializeRound(bool isRetry) { Debug.Log("Starting round: " + (round + 1)); // destroy previous area if (playArea != null) { Destroy(playArea.gameObject); } // Play a random track SoundManager.instance.PlayRandomRoundClip(); // save to restore later roundStartLives = livesLeft; // Load the images CharacterFile.RoundImages roundData = sourceFile.LoadRound(round); // create a fresh play area System.Type bossType = roundBoss[round].GetType(); //bossType = typeof(Slimy); playArea = Instantiate(sourcePlayArea, sourcePlayArea.transform.parent, true); playArea.gameObject.SetActive(true); playArea.Setup(roundData.baseImage, roundData.shadowImage, bossType); Debug.Log("Boss: " + bossType.Name.ToString()); // reset percentage tracker to zero lastPercentage = 0; // reset score score = 0; // check when the player spawns to count lives / game overs playArea.player.spawned += OnPlayerSpawned; playArea.player.died += OnPlayerDied; // Let the camera know it can start tracking the player cameraController.StartTracking(playArea); // reset the UI UI.instance.Reset( livesLeft, Config.instance.clearPercentage, Config.instance.roundTime, Skill.instance.maxTime, Skill.instance.remainingTime); // reset the timer Timer.instance.ResetTimer(Config.instance.roundTime); // Hide the player playArea.player.Hide(); // Hide the transition #if UNITY_EDITOR if (Transition.instance != null) { yield return(StartCoroutine(Transition.instance.Hide())); } #else yield return(StartCoroutine(Transition.instance.Hide())); #endif // play the intro animation for the round yield return(StartCoroutine(UI.instance.roundStart.Show(round, SoundManager.instance.currentBGM))); // Create a square that randomly changes sizes // until the fire button gets pressed const float Area = 50 * 50; const int MaxWidth = 100; const int MinWidth = 20; const float FlickDelay = 0.075f; initialSquare.gameObject.SetActive(true); initialSquare.mesh.triangles = new int[] { 0, 1, 2, 3, 0, 2 }; float w = 0, h = 0; while (true) { w = Random.Range(MinWidth, MaxWidth); h = Area / w; w /= 2; h /= 2; Vector3[] corners = new Vector3[] { new Vector3(-w, -h), new Vector3(-w, h), new Vector3(w, h), new Vector3(w, -h), }; initialSquare.mesh.vertices = corners; // wait until the next random square // or cancel wait if user presses button float wait = FlickDelay; while (wait >= 0 && !Input.GetButtonDown("Cut")) { wait -= Time.deltaTime; yield return(null); } if (wait > 0) { break; } } // hide the round start UI UI.instance.roundStart.Hide(); IntRect rect = new IntRect() { x = playArea.player.x - Mathf.FloorToInt(w), y = playArea.player.y - Mathf.FloorToInt(h), width = Mathf.RoundToInt(w * 2), height = Mathf.RoundToInt(h * 2) }; // re-enable the player and put it in a corner of the square playArea.player.Spawn(rect.x, rect.y); // set callbacks to check game progress playArea.mask.maskCleared += OnMaskCleared; // create the square and destroy the "preview" playArea.CreateStartingZone(rect); initialSquare.gameObject.SetActive(false); // now that the play area has colliders, // place the boss safely in the shadow playArea.boss.gameObject.SetActive(true); playArea.boss.PlaceRandomly(); playArea.boss.minionKilled += OnMinionKilled; playArea.boss.Run(); // Let the bonus manager know a new round started BonusItemManager.instance.InitializeRound(playArea, round, isRetry); // start tracking it UI.instance.bossTracker.StartTracking(playArea.boss); // start timer Timer.instance.StartTimer(); // Handle the pause from here on out StartCoroutine("PauseHandler"); yield break; }