public void FadeCanvasGroupOut(CanvasGroup canvasGroup, Action callback) { // Find out if the renderer we want to fade is already fading KeyValuePair <CanvasGroup, Coroutine> existingFade = Instance.FadingRenderers.Find(renderCoroutinePair => renderCoroutinePair.Key == canvasGroup); // If it's already fading, stop the fade if (existingFade.Equals(default(KeyValuePair <CanvasRenderer, Coroutine>)) && existingFade.Value != null) { Instance.StopCoroutine(existingFade.Value); } // Setup a new fade routine for the renderer Coroutine fade = null; KeyValuePair <CanvasGroup, Coroutine> replacementFade = new KeyValuePair <CanvasGroup, Coroutine>(canvasGroup, fade); Action completionAction = () => { Instance.FadingRenderers.Remove(replacementFade); Instance.CurrentOverlays.Remove(canvasGroup); if (callback != null) { callback(); } }; fade = Instance.StartCoroutine(FadeUtility.UIAlphaFade(canvasGroup, canvasGroup.alpha, 0f, FadeDuration, FadeUtility.EaseType.InOut, completionAction)); Instance.FadingRenderers.Remove(existingFade); // Remove the previous fade Instance.FadingRenderers.Add(replacementFade); // Add the new fade }
void Update() { this.Duration -= Time.deltaTime; if (this.Duration <= 0 && this.Fading == null) { this.Fading = StartCoroutine(FadeUtility.UIAlphaFade(this.CanvasGroup, this.CanvasGroup.alpha, 0, FadeDuration, FadeUtility.EaseType.InOut, () => { this.Fading = null; this.Remove(); })); } }
public void Update() { switch (State) { case GameStateComponentState.CountDown: break; case GameStateComponentState.InGame: // no more time or the user hit the debug command to go to the next level ? if (TimeRemaining <= 0 || CheckDebugKey(KeyCode.Slash)) { // fade the screen to black and load the next scene FadeUtility.FadeToNextScene(loadSpinnerObject, webComponent, () => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1)); State = GameStateComponentState.GameCompleted; } else { TimeRemaining = Mathf.Max(0, TimeRemaining - Time.deltaTime); // check if the user wants to pause the game if (Input.GetKeyUp(KeyCode.P)) { Time.timeScale = 0.0f; State = GameStateComponentState.Paused; } // debug command to decrease the time by 3 minutes else if (CheckDebugKey(KeyCode.Z)) { TimeRemaining = Mathf.Max(0, TimeRemaining - 180); } } break; case GameStateComponentState.Paused: if (Input.GetKeyUp(KeyCode.P)) { Time.timeScale = 1.0f; State = GameStateComponentState.InGame; } break; case GameStateComponentState.LostServerConnection: break; case GameStateComponentState.GameCompleted: // just (wait for the server to ack and) do nothing break; } }
public void Show(string tooltip, float duration) { if (!GUIManager.Instance.Tooltips.Contains(this)) { GUIManager.Instance.Tooltips.Add(this); } this.Duration = duration; this.Text.text = tooltip; if (!this.FadingIn && this.CanvasGroup.alpha != 1) { if (this.Fading != null) { StopCoroutine(this.Fading); } this.Fading = StartCoroutine(FadeUtility.UIAlphaFade(this.CanvasGroup, this.CanvasGroup.alpha, 1, FadeDuration, FadeUtility.EaseType.InOut, () => { this.Fading = null; this.FadingIn = false; })); this.FadingIn = true; } }
public void OnClick() { FadeUtility.FadeToNextScene(loadScreenSpinner, _webCom, () => SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1)); }