Skip to content

Commit ebc4c86

Browse files
committed
refactor(Scene): Rename JCS_Logo to JCS_DelayLoadSceneEvent
1 parent 4d475fb commit ebc4c86

File tree

8 files changed

+63
-63
lines changed

8 files changed

+63
-63
lines changed

Assets/JCSUnity/Scripts/Events/Scene.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/JCSUnity/Scripts/JCS_Logo.cs renamed to Assets/JCSUnity/Scripts/Events/Scene/JCS_DelayLoadSceneEvent.cs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* $File: JCS_Logo.cs $
2+
* $File: JCS_DelayLoadSceneEvent.cs $
33
* $Date: $
44
* $Revision: $
55
* $Creator: Jen-Chieh Shen $
@@ -12,17 +12,21 @@
1212
namespace JCSUnity
1313
{
1414
/// <summary>
15-
/// Logo object for next scene.
15+
/// Delay seconds before loading a scene.
1616
/// </summary>
17-
public class JCS_Logo : MonoBehaviour
17+
public class JCS_DelayLoadSceneEvent : MonoBehaviour
1818
{
1919
/* Variables */
2020

21-
[Separator("Runtime Variables (JCS_Logo)")]
21+
[Separator("Runtime Variables (JCS_DelayLoadSceneEvent)")]
2222

2323
[Tooltip("Next scene to load; if empy, load the next scene instead.")]
2424
[SerializeField]
25-
private string mNextLevel = "JCS_AppCloseSimulate";
25+
private string mNextLevel = "";
26+
27+
[Tooltip("Reload the current scene, and ignore the target scene name.")]
28+
[SerializeField]
29+
public bool mReloadScene = false;
2630

2731
[Tooltip("Second to show logo and load to the next scene.")]
2832
[SerializeField]
@@ -58,20 +62,10 @@ private void Update()
5862

5963
if (mDelayTime < mDelayTimer)
6064
{
61-
LoadLevel();
62-
}
63-
}
65+
string sceneName = JCS_SceneManager.GetSceneNameByOption(mNextLevel, mReloadScene);
6466

65-
private void LoadLevel()
66-
{
67-
var sm = JCS_SceneManager.instance;
68-
69-
string sceneName = mNextLevel;
70-
71-
if (sceneName == "")
72-
sceneName = sm.NextSceneName();
73-
74-
sm.LoadScene(sceneName);
67+
JCS_SceneManager.instance.LoadScene(sceneName);
68+
}
7569
}
7670
}
7771
}

Assets/JCSUnity/Scripts/JCS_Logo.cs.meta renamed to Assets/JCSUnity/Scripts/Events/Scene/JCS_DelayLoadSceneEvent.cs.meta

File renamed without changes.

Assets/JCSUnity/Scripts/Managers/JCS_SceneManager.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,9 @@ public void ReloadScene(float fadeInTime, Color screenColor, bool keepBGM)
504504
#region Next Scene
505505

506506
/// <summary>
507-
/// Return the next scene.
507+
/// Return the next scene name.
508508
/// </summary>
509-
public string NextSceneName(int offset = 1)
509+
public static string NextSceneName(int offset = 1)
510510
{
511511
int nextIndex = SceneManager.GetActiveScene().buildIndex + offset;
512512

@@ -611,6 +611,27 @@ public void LoadNextScene(float fadeInTime, Color screenColor, bool keepBGM)
611611

612612
#endregion
613613

614+
/// <summary>
615+
/// Return the scene name by their options.
616+
/// </summary>
617+
/// <param name="sceneName"> The default scene name. </param>
618+
/// <param name="reload"> Reload it? </param>
619+
/// <param name="offset"> Offset for next scene's build index. </param>
620+
public static string GetSceneNameByOption(string sceneName, bool reload, int offset = 1)
621+
{
622+
if (reload)
623+
{
624+
return SceneManager.GetActiveScene().name;
625+
}
626+
else
627+
{
628+
if (sceneName.IsNullOrEmpty())
629+
sceneName = NextSceneName(offset);
630+
}
631+
632+
return sceneName;
633+
}
634+
614635
/// <summary>
615636
/// Check is loading the scene or not.
616637
/// </summary>

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,9 @@ public override void OnClick()
6161
return;
6262
}
6363

64-
string sceneName = mSceneName;
64+
string sceneName = JCS_SceneManager.GetSceneNameByOption(mSceneName, mReloadScene);
6565

66-
var sm = JCS_SceneManager.instance;
67-
68-
if (mReloadScene)
69-
{
70-
// assign current scene name
71-
sceneName = SceneManager.GetActiveScene().name;
72-
}
73-
else
74-
{
75-
if (sceneName == "")
76-
sceneName = sm.NextSceneName();
77-
}
78-
79-
sm.LoadScene(sceneName, mScreenColor, mKeppBGM);
66+
JCS_SceneManager.instance.LoadScene(sceneName, mScreenColor, mKeppBGM);
8067
}
8168
}
8269
}

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

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,9 @@ public override void OnClick()
6161
return;
6262
}
6363

64-
var sm = JCS_SceneManager.instance;
64+
string sceneName = JCS_SceneManager.GetSceneNameByOption(mSceneName, mReloadScene);
6565

66-
string sceneName = mSceneName;
67-
68-
if (mReloadScene)
69-
{
70-
// assign current scene name
71-
sceneName = SceneManager.GetActiveScene().name;
72-
}
73-
else
74-
{
75-
if (sceneName == "")
76-
sceneName = sm.NextSceneName();
77-
}
78-
79-
sm.LoadScene(sceneName, mScreenColor, mKeppBGM);
66+
JCS_SceneManager.instance.LoadScene(sceneName, mScreenColor, mKeppBGM);
8067
}
8168
}
8269
}

docs/ScriptReference/JCS_Logo.md renamed to docs/ScriptReference/Events/Scene/JCS_DelayLoadSceneEvent.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
# JCS_Logo
1+
# JCS_DelayLoadSceneEvent
22

3-
A simple logo object.It will load and show briefly before loading the next scene.
3+
A simple logo object. It will load and show briefly before loading the next scene.
44

55
## Variables
66

7-
| Name | Description |
8-
|:---------------|:----------------------------------------------------------|
9-
| mNextLevel | Next scene to load; if empy, load the next scene instead. |
10-
| mDelayTime | Time to show logo. |
11-
| mDeltaTimeType | Type of the delta time. |
7+
| Name | Description |
8+
|:---------------|:------------------------------------------------------------|
9+
| mNextLevel | Next scene to load; if empy, load the next scene instead. |
10+
| mReloadScene | Reload the current scene, and ignore the target scene name. |
11+
| mDelayTime | Time to show logo. |
12+
| mDeltaTimeType | Type of the delta time. |

docs/ScriptReference/Managers/JCS_SceneManager.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ Better version of scene manager.
1818

1919
## Functions
2020

21-
| Name | Description |
22-
|:-----------------|:-----------------------------------|
23-
| LoadScene | Load the target scene. |
24-
| ReloadScene | Reload the current scene. |
25-
| LoadNextScene | Load the next scene. |
26-
| IsSwitchingScene | Check is loading the scene or not. |
21+
| Name | Description |
22+
|:---------------------|:----------------------------------------|
23+
| LoadScene | Load the target scene. |
24+
| ReloadScene | Reload the current scene. |
25+
| LoadNextScene | Load the next scene. |
26+
| NextSceneName | Return the next scene name. |
27+
| GetSceneNameByOption | Return the scene name by their options. |
28+
| IsSwitchingScene | Check is loading the scene or not. |

0 commit comments

Comments
 (0)