Gametime has a value for pauseLevel, an int value which specifies different tiers of pausing in the game. Generally a value of 0 means the game is not paused, and a value higher would imply there is some amount of pause.
While some games may just have two states, other projects will have multiple states, such as a level where enemies and projectiles stop moving, but the player can continue to work with the UI, while a higher pause level may keep the player from working with the UI, and only allow operation of the game settings menu.
Variables
// The active pauseLevelpublicint pauseLevel =0;// This value is set by the script, and records the most recent pauseLevel[SerializeField] privateint lastPauseLevel =0;// If not -1, when this script is awakened, game will pause to this levelpublicint pauseLevelOnAwake =-1;// If not -1, game will pause to this level when we change scenes.publicint pauseLevelWhenSceneChanges =-1; // If not -1, game will pause to this level when a new scene is loaded.publicint pauseLevelWhenNewSceneLoaded =-1; // Gametime will not advance if pauseLevel >= this value.publicint stopTimeOnPauseLevel =1;
Methods
// Set the pauseLevel to the maximum of pauseLevel or newLevel// If saveLastPauseLevel is true, lastPauseLevel will be saved only if pauseLevel// does not equal newLevel.publicvoidSetPauseLevelMax(int newLevel,bool saveLastPauseLevel =true)// Set the pauseLevel to the minimum of pauseLevel or newLevelpublic void SetPauseLevelMin(int newLevel)// Reset pauseLevel to the value of lastPauseLevelpublic void ResetToLastPauseLevel()
Examples
This example comes from DialoguePanel.cs in the Party Base RPG demo game. When the panel is enabled, the game should set to a pauseLevel that is set on the script itself.
usingstaticInfinityPBR.Modules.Timeboard;//........// These values are set in the Inspectorpublicint pauseLevelOnEnable =2;publicbool revertPauseLevelOnDisable =true;// On enable, set the pause level to pauseLevelOnEnableprivatevoidOnEnable() =>StartCoroutine(SetPauseLevel());// We require timeboard, which is a singleton, so ensure it is// available before we try to utilize it.privateIEnumeratorSetPauseLevel(){while (timeboard ==null)yieldreturnnull; // Access gametime via timeboard.gametimetimeboard.gametime.SetPauseLevelMax(pauseLevelOnEnable);}// When our panel closes, we reset to the last pause level, whatever that was.privatevoidOnDisable() =>timeboard.gametime.ResetToLastPauseLevel();