Beispiel #1
0
        public static PauseLock PauseGame(PauseLockType type, object token)
        {
            var pLock = new PauseLock(type, token);

            Instance.AddPauseLock(pLock);
            return(pLock);
        }
Beispiel #2
0
 public WaitForSecondsEx(float time, bool skippable = false, PauseLockType?lowestPauseState = null, bool useRealtime = false)
 {
     TimeToWait        = time;
     Skippable         = skippable;
     AllowWhenPaused   = lowestPauseState.HasValue;
     HighestPauseState = lowestPauseState ?? default;
     UseRealtime       = useRealtime;
 }
Beispiel #3
0
        /// <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();
        }
Beispiel #4
0
        private void ApplyPauseLock(PauseLockType newState)
        {
            //stop time (not all that failsafe, it turns out)
            Time.timeScale      = 0;
            AudioListener.pause = true;

            //uncapture mouse
            DoUncapture();

            //send message and set state
            if (QdmsMessageBus.Instance != null) //it's possible for this to run after the message bus is destroyed
            {
                QdmsMessageBus.Instance.PushBroadcast(new PauseLockMessage(newState));
            }

            PauseLockState = newState;
        }
Beispiel #5
0
        /// <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
        }
Beispiel #6
0
 public PauseLock(PauseLockType type, object owner)
 {
     Type  = type;
     Owner = owner;
 }