private void Update() { if (!((LockPauseModule.GetPauseLockState() ?? PauseLockType.AllowCutscene) > PauseLockType.AllowMenu)) //handle pauses { return; } if (LockPauseModule.GetInputLockState() == InputLockType.All) { return; } //this probably won't work, but it's supposed to reselect after a return from the menu if (EventSystem.currentSelectedGameObject == null || !EventSystem.currentSelectedGameObject.activeInHierarchy) { SelectButton(SelectedButton); } //update our view of SelectedButton if (EventSystem.currentSelectedGameObject != CurrentButtons[SelectedButton].gameObject) { int newIndex = CurrentButtons.IndexOf(EventSystem.currentSelectedGameObject.GetComponent <Button>()); if (newIndex >= 0) { SelectedButton = newIndex; } //Debug.Log($"selected {SelectedButton}"); } }
/// <summary> /// Waits a specified number of seconds in scaled time (respecting pause state), can be skipped with skip button /// </summary> /// <remarks>Can only be used from the main thread</remarks> public static async Task DelayScaled(float time, PauseLockType lowestPauseState, bool useRealtime = false) { for (float elapsed = 0; elapsed < time;) { await Task.Yield(); var pls = LockPauseModule.GetPauseLockState(); if (pls == null || pls >= lowestPauseState) { float timeScale = useRealtime ? 1 : (Mathf.Approximately(Time.timeScale, 0) ? 1 : Time.timeScale); elapsed += Time.unscaledDeltaTime * timeScale; } } await Task.Yield(); }
/// <summary> /// Waits for specified time (respecting pause state), can be skipped with skip button /// </summary> public static IEnumerator WaitForSeconds(float time, PauseLockType lowestPauseState, bool useRealtime = false) { for (float elapsed = 0; elapsed < time;) { if (RequestedSkip) { break; } yield return(null); var pls = LockPauseModule.GetPauseLockState(); if (pls == null || pls >= lowestPauseState) { float timeScale = useRealtime ? 1 : (Mathf.Approximately(Time.timeScale, 0) ? 1 : Time.timeScale); elapsed += Time.unscaledDeltaTime * timeScale; } } yield return(null); //necessary for debouncing }