Skip to content

Commit

Permalink
feat: Add custom switch scene
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 16, 2024
1 parent 51839ed commit 84f5f4b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Assets/JCSUnity/Scripts/Enums/JCS_SwitchSceneType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace JCSUnity
/// </summary>
public enum JCS_SwitchSceneType
{
NONE,

BLACK_SCREEN,
SLIDE_SCREEN,
NONE, /* 不做任何處理 */
CUSTOM, /* 客製 */
BLACK_SCREEN, /* 黑屏 */
SLIDE_SCREEN, /* 滑屏 */
}
}
55 changes: 46 additions & 9 deletions Assets/JCSUnity/Scripts/Managers/JCS_SceneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class JCS_SceneManager : JCS_Manager<JCS_SceneManager>
{
/* Variables */

public EmptyFunction onSwitchSceneInit = null;
public EmptyFunction onSwitchSceneLoad = null;
public EmptyBoolFunction onSwitchSceneIn = null;
public EmptyBoolFunction onSwitchSceneOut = null;

// Async loading scene operation. (thread)
private AsyncOperation mAsyncOperation = null;

Expand Down Expand Up @@ -141,6 +146,12 @@ private void Start()

switch (mSwitchSceneType)
{
case JCS_SwitchSceneType.CUSTOM:
{
if (onSwitchSceneInit != null)
onSwitchSceneInit.Invoke();
}
break;
case JCS_SwitchSceneType.BLACK_SCREEN:
{
// get the current screen color.
Expand Down Expand Up @@ -304,10 +315,10 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
}
#endif

var scenes = JCS_SceneSettings.instance;
var scs = JCS_SceneSettings.instance;

// if is loading already, dont load it agian
if (scenes.SWITCHING_SCENE)
if (scs.SWITCHING_SCENE)
return;

// set the next scene name
Expand All @@ -327,6 +338,13 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo

switch (mSwitchSceneType)
{
case JCS_SwitchSceneType.CUSTOM:
{
if (onSwitchSceneLoad != null)
onSwitchSceneLoad.Invoke();
}
break;

case JCS_SwitchSceneType.BLACK_SCREEN:
{
// move to the last child in order
Expand Down Expand Up @@ -357,14 +375,14 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
break;
}

var ss = JCS_SoundSettings.instance;
var sos = JCS_SoundSettings.instance;

ss.KEEP_BGM_SWITCH_SCENE = keepBGM;
sos.KEEP_BGM_SWITCH_SCENE = keepBGM;

if (!keepBGM)
{
// start fading sound
if (ss.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE)
if (sos.SMOOTH_SWITCH_SOUND_BETWEEN_SCENE)
{
// get the component.
if (mFadeSound == null)
Expand All @@ -378,7 +396,7 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
}

// start check to switch scene or not
scenes.SWITCHING_SCENE = true;
scs.SWITCHING_SCENE = true;
}

/// <summary>
Expand Down Expand Up @@ -488,14 +506,33 @@ public bool IsSwitchingScene()
/// </summary>
private void DoSwitchScene()
{
var scenes = JCS_SceneSettings.instance;
var ss = JCS_SceneSettings.instance;

// check if during the switch scene?
if (!scenes.SWITCHING_SCENE)
if (!ss.SWITCHING_SCENE)
return;

switch (mSwitchSceneType)
{
case JCS_SwitchSceneType.CUSTOM:
{
if (onSwitchSceneIn != null)
{
if (onSwitchSceneIn.Invoke())
{
// load the scene if is ready
mAsyncOperation.allowSceneActivation = true;
}
}

if (onSwitchSceneOut != null)
{
if (onSwitchSceneOut.Invoke())
ss.SWITCHING_SCENE = false;
}
}
break;

case JCS_SwitchSceneType.BLACK_SCREEN:
{
if (mBlackScreen.IsFadeIn())
Expand All @@ -508,7 +545,7 @@ private void DoSwitchScene()

if (inNewScene && mBlackScreen.IsFadeOut())
{
scenes.SWITCHING_SCENE = false;
ss.SWITCHING_SCENE = false;
}
}
break;
Expand Down

0 comments on commit 84f5f4b

Please sign in to comment.