Skip to content

Commit f6d0ab7

Browse files
committed
feat: Load next scene when scene is empty
1 parent 0a390e7 commit f6d0ab7

File tree

4 files changed

+140
-11
lines changed

4 files changed

+140
-11
lines changed

Assets/JCSUnity/Scripts/Managers/JCS_SceneManager.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ private void Update()
210210
DoSwitchScene();
211211
}
212212

213+
#region Load Scene
214+
213215
/// <summary>
214216
/// Load the target scene.
215217
/// </summary>
@@ -399,6 +401,10 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
399401
scs.SWITCHING_SCENE = true;
400402
}
401403

404+
#endregion
405+
406+
#region Reload Scene
407+
402408
/// <summary>
403409
/// Reload the current scene.
404410
/// </summary>
@@ -492,6 +498,115 @@ public void ReloadScene(float fadeInTime, Color screenColor, bool keepBGM)
492498
LoadScene(sceneName, fadeInTime, screenColor, keepBGM);
493499
}
494500

501+
#endregion
502+
503+
#region Next Scene
504+
505+
/// <summary>
506+
/// Return the next scene.
507+
/// </summary>
508+
public Scene NextScene(int offset = 1)
509+
{
510+
int nextIndex = SceneManager.GetActiveScene().buildIndex + offset;
511+
512+
return SceneManager.GetSceneByBuildIndex(nextIndex);
513+
}
514+
515+
/// <summary>
516+
/// Load the next scene.
517+
/// </summary>
518+
public void LoadNextScene()
519+
{
520+
// NOTE(jenchieh): get the fade in time base on
521+
// the scene setting and scene manager specific.
522+
float fadeInTime = JCS_SceneSettings.instance.SceneFadeInTimeBaseOnSetting();
523+
524+
// load scene and pass the value in.
525+
LoadNextScene(fadeInTime);
526+
}
527+
528+
/// <summary>
529+
/// Load the next scene.
530+
/// </summary>
531+
/// <param name="fadeInTime"> Time to fade in. </param>
532+
public void LoadNextScene(float fadeInTime)
533+
{
534+
LoadNextScene(fadeInTime, false);
535+
}
536+
537+
/// <summary>
538+
/// Load the next scene.
539+
/// </summary>
540+
/// <param name="screenColor"> Screen color to fade in/out. </param>
541+
public void LoadNextScene(Color screenColor)
542+
{
543+
var ss = JCS_SceneSettings.instance;
544+
545+
// NOTE(jenchieh): get the fade in time base on the scene setting
546+
// and scene manager specific.
547+
float fadeInTime = ss.SceneFadeInTimeBaseOnSetting();
548+
549+
LoadNextScene(fadeInTime, screenColor, false);
550+
}
551+
552+
/// <summary>
553+
/// Load the next scene.
554+
/// </summary>
555+
/// <param name="keepBGM"> Set to true if keep background music playing. </param>
556+
public void LoadNextScene(bool keepBGM)
557+
{
558+
var ss = JCS_SceneSettings.instance;
559+
560+
// NOTE(jenchieh): get the fade in time base on the scene setting
561+
// and scene manager specific.
562+
float fadeInTime = ss.SceneFadeInTimeBaseOnSetting();
563+
564+
LoadNextScene(fadeInTime, ss.SCREEN_COLOR, keepBGM);
565+
}
566+
567+
/// <summary>
568+
/// Load the next scene.
569+
/// </summary>
570+
/// <param name="fadeInTime"> Time to fade in. </param>
571+
/// <param name="keepBGM"> Set to true if keep background music playing. </param>
572+
public void LoadNextScene(float fadeInTime, bool keepBGM)
573+
{
574+
var sceneS = JCS_SceneSettings.instance;
575+
576+
LoadNextScene(fadeInTime, sceneS.SCREEN_COLOR, keepBGM);
577+
}
578+
579+
/// <summary>
580+
/// Load the next scene.
581+
/// </summary>
582+
/// <param name="screenColor"> Screen color to fade in/out. </param>
583+
/// <param name="keepBGM"> Set to true if keep background music playing. </param>
584+
public void LoadNextScene(Color screenColor, bool keepBGM)
585+
{
586+
var ss = JCS_SceneSettings.instance;
587+
588+
// NOTE(jenchieh): get the fade in time base on the scene setting
589+
// and scene manager specific.
590+
float fadeInTime = ss.SceneFadeInTimeBaseOnSetting();
591+
592+
LoadNextScene(fadeInTime, screenColor, keepBGM);
593+
}
594+
595+
/// <summary>
596+
/// Load the next scene.
597+
/// </summary>
598+
/// <param name="fadeInTime"> Time to fade in. </param>
599+
/// <param name="screenColor"> Screen color to fade in/out. </param>
600+
/// <param name="keepBGM"> Set to true if keep background music playing. </param>
601+
public void LoadNextScene(float fadeInTime, Color screenColor, bool keepBGM)
602+
{
603+
string sceneName = NextScene().name;
604+
605+
LoadScene(sceneName, fadeInTime, screenColor, keepBGM);
606+
}
607+
608+
#endregion
609+
495610
/// <summary>
496611
/// Check is loading the scene or not.
497612
/// </summary>

Assets/JCSUnity/Scripts/UI/Button/Scene/JCS_LoadSceneButton.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class JCS_LoadSceneButton : JCS_Button
2525
[SerializeField]
2626
private JCS_PlatformType mPlatformType = JCS_PlatformType.NONE;
2727

28-
[Tooltip("Scene name you want to load the scene.")]
28+
[Tooltip("Scene name you want to load the scene; if empy, load the next scene instead.")]
2929
[SerializeField]
3030
private string mSceneName = "";
3131

@@ -63,13 +63,20 @@ public override void OnClick()
6363

6464
string sceneName = mSceneName;
6565

66+
var sm = JCS_SceneManager.instance;
67+
6668
if (mReloadScene)
6769
{
6870
// assign current scene name
6971
sceneName = SceneManager.GetActiveScene().name;
7072
}
73+
else
74+
{
75+
if (sceneName == "")
76+
sceneName = sm.NextScene().name;
77+
}
7178

72-
JCS_SceneManager.instance.LoadScene(sceneName, mScreenColor, mKeppBGM);
79+
sm.LoadScene(sceneName, mScreenColor, mKeppBGM);
7380
}
7481
}
7582
}

Assets/JCSUnity/Scripts/UI/Button/Scene/JCS_LoadSceneGamePadButton.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class JCS_LoadSceneGamepadButton : JCS_GamepadButton
2525
[SerializeField]
2626
private JCS_PlatformType mPlatformType = JCS_PlatformType.NONE;
2727

28-
[Tooltip("Scene name you want to load the scene.")]
28+
[Tooltip("Scene name you want to load the scene; if empy, load the next scene instead.")]
2929
[SerializeField]
3030
private string mSceneName = "";
3131

@@ -61,15 +61,22 @@ public override void OnClick()
6161
return;
6262
}
6363

64+
var sm = JCS_SceneManager.instance;
65+
6466
string sceneName = mSceneName;
6567

6668
if (mReloadScene)
6769
{
6870
// assign current scene name
6971
sceneName = SceneManager.GetActiveScene().name;
7072
}
73+
else
74+
{
75+
if (sceneName == "")
76+
sceneName = sm.NextScene().name;
77+
}
7178

72-
JCS_SceneManager.instance.LoadScene(sceneName, mScreenColor, mKeppBGM);
79+
sm.LoadScene(sceneName, mScreenColor, mKeppBGM);
7380
}
7481
}
7582
}

docs/ScriptReference/UI/Button/Scene/JCS_LoadSceneButton.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Button will load the target scene.
44

55
## Variables
66

7-
| Name | Description |
8-
|:--------------|:---------------------------------------------------------------------------|
9-
| mPlatformType | Limit to this platform only. NONE, will just load the scene without limit. |
10-
| mSceneName | Scene name you want to load the scene. |
11-
| mReloadScene | Reload the current scene, and ignore the target scene name. |
12-
| mScreenColor | Screen color when load the scene. |
13-
| mKeppBGM | Keep BGM playing when load scene. |
7+
| Name | Description |
8+
|:--------------|:-----------------------------------------------------------------------------|
9+
| mPlatformType | Limit to this platform only. NONE, will just load the scene without limit. |
10+
| mSceneName | Scene name you want to load the scene; if empy, load the next scene instead. |
11+
| mReloadScene | Reload the current scene, and ignore the target scene name. |
12+
| mScreenColor | Screen color when load the scene. |
13+
| mKeppBGM | Keep BGM playing when load scene. |

0 commit comments

Comments
 (0)