Skip to content

Commit 628c536

Browse files
committed
feat(Manager): Add toggle pause function
1 parent 4ef2170 commit 628c536

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

Assets/JCSUnity/Scripts/Managers/JCS_PauseManager.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public class JCS_PauseManager : JCS_Manager<JCS_PauseManager>
2929
[ReadOnly]
3030
private float mTimeScale = 1.0f;
3131

32-
[Tooltip("Test this module?")]
32+
[Tooltip("Turn on to test this behaviour.")]
3333
[SerializeField]
34-
private bool mTestWithKey = false;
34+
private bool mTest = false;
3535

3636
[Tooltip("Key to toggle game pause/unpause.")]
3737
[SerializeField]
@@ -139,7 +139,7 @@ private void Update()
139139
#if UNITY_EDITOR
140140
private void TestPauseGame()
141141
{
142-
if (!mTestWithKey)
142+
if (!mTest)
143143
return;
144144

145145
if (Input.GetKeyDown(mToggleGamePause))
@@ -181,7 +181,7 @@ public void ResetState()
181181
mTargetTimeScale = mDefaultTimeScale;
182182
Time.timeScale = mDefaultTimeScale;
183183

184-
PauseTheWholeGame(false);
184+
SetPause(false);
185185
}
186186

187187
/// <summary>
@@ -196,7 +196,7 @@ public void Pause()
196196
else
197197
Time.timeScale = 0.0f;
198198

199-
PauseTheWholeGame(true);
199+
SetPause(true);
200200
}
201201

202202
/// <summary>
@@ -211,20 +211,30 @@ public void Unpause()
211211
else
212212
Time.timeScale = mDefaultTimeScale;
213213

214-
PauseTheWholeGame(false);
214+
SetPause(false);
215215
}
216216

217217
/// <summary>
218-
/// Pause/Unpause the whole game.
218+
/// Toggle between pause/unpause the game.
219219
/// </summary>
220-
public void PauseTheWholeGame(bool act = true)
220+
public void TogglePause()
221+
{
222+
if (mPaused)
223+
Unpause();
224+
else
225+
Pause();
226+
}
227+
228+
/// <summary>
229+
/// Set pause/unpause the game.
230+
/// </summary>
231+
public void SetPause(bool act = true)
221232
{
222233
foreach (JCS_PauseAction pauseAction in mPauseActions)
223234
{
224235
if (pauseAction == null)
225236
continue;
226237

227-
228238
// NOTE(jenchieh): the act should be opposite with the
229239
// enable /disable.
230240

docs/ScriptReference/Managers/JCS_PauseManager.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ need the pause manager to add it to `JCS_Managers` transform in the Hierarchy.
1414

1515
## Functions
1616

17-
| Name | Description |
18-
|:------------------|:-------------------------------------------------------------------------------------------------------|
19-
| AddActionToList | Add the pause action to the list of pause action list, in order to get manage by this "pause manager". |
20-
| ResetState | Reset pause state. |
21-
| Pause | Pause the game. |
22-
| Unpase | Unpause the game. |
23-
| PauseTheWholeGame | ause/Unpause the whole game. |
17+
| Name | Description |
18+
|:----------------|:-------------------------------------------------------------------------------------------------------|
19+
| AddActionToList | Add the pause action to the list of pause action list, in order to get manage by this "pause manager". |
20+
| ResetState | Reset pause state. |
21+
| Pause | Pause the game. |
22+
| Unpase | Unpause the game. |
23+
| TogglePause | Toggle between pause/unpause the game. |
24+
| SetPause | Set pause/unpause the game. |

0 commit comments

Comments
 (0)