Skip to content

Commit b9f80d5

Browse files
committed
fix: scene transition order execution
1 parent c2095f6 commit b9f80d5

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

Assets/JCSUnity/Scripts/Effects/JCS_FadeObject.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,24 +131,16 @@ private void Test()
131131
#endif
132132

133133
/// <summary>
134-
/// Is the fade object fade in?
134+
/// Return true if the object is fade in.
135135
/// </summary>
136-
/// <returns>
137-
/// true : is fade in.
138-
/// false : not fade in yet.
139-
/// </returns>
140136
public bool IsFadeIn()
141137
{
142138
return (this.mAlpha >= mFadeInAmount);
143139
}
144140

145141
/// <summary>
146-
/// Is the fade object fade out?
142+
/// Return true if the object is fade out.
147143
/// </summary>
148-
/// <returns>
149-
/// true : is fade out.
150-
/// false : not fade out yet.
151-
/// </returns>
152144
public bool IsFadeOut()
153145
{
154146
return (this.mAlpha <= mFadeOutAmount);

Assets/JCSUnity/Scripts/Managers/JCS_SceneManager.cs

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,10 @@ private void Start()
203203

204204
private void Update()
205205
{
206-
DoSwitchScene();
206+
if (IsEnteringSwitchScene())
207+
DoEnterSwitchScene();
208+
else
209+
DoExitSwitchScene();
207210
}
208211

209212
#region Load Scene
@@ -433,7 +436,7 @@ public bool IsSwitchingScene()
433436
/// <summary>
434437
/// Do the async switch scene.
435438
/// </summary>
436-
private void DoSwitchScene()
439+
private void DoEnterSwitchScene()
437440
{
438441
var ss = JCS_SceneSettings.instance;
439442

@@ -452,22 +455,51 @@ private void DoSwitchScene()
452455
AllowSceneActivation();
453456
}
454457
}
458+
}
459+
break;
455460

456-
if (onSwitchSceneOut != null)
461+
case JCS_SwitchSceneType.BLACK_SCREEN:
462+
{
463+
if (mBlackScreen.IsFadeIn())
457464
{
458-
if (onSwitchSceneOut.Invoke())
459-
ss.SWITCHING_SCENE = false;
465+
AllowSceneActivation();
460466
}
461467
}
462468
break;
463469

464-
case JCS_SwitchSceneType.BLACK_SCREEN:
470+
case JCS_SwitchSceneType.SLIDE_SCREEN:
465471
{
466-
if (mBlackScreen.IsFadeIn())
472+
if (mBlackSlideScreen.IsDoneSliding())
467473
{
468474
AllowSceneActivation();
469475
}
476+
}
477+
break;
478+
}
479+
}
480+
481+
private void DoExitSwitchScene()
482+
{
483+
var ss = JCS_SceneSettings.instance;
484+
485+
// check if during the switch scene?
486+
if (!ss.SWITCHING_SCENE)
487+
return;
488+
489+
switch (mSwitchSceneType)
490+
{
491+
case JCS_SwitchSceneType.CUSTOM:
492+
{
493+
if (onSwitchSceneOut != null)
494+
{
495+
if (onSwitchSceneOut.Invoke())
496+
ss.SWITCHING_SCENE = false;
497+
}
498+
}
499+
break;
470500

501+
case JCS_SwitchSceneType.BLACK_SCREEN:
502+
{
471503
if (mBlackScreen.IsFadeOut())
472504
{
473505
ss.SWITCHING_SCENE = false;
@@ -479,7 +511,7 @@ private void DoSwitchScene()
479511
{
480512
if (mBlackSlideScreen.IsDoneSliding())
481513
{
482-
AllowSceneActivation();
514+
ss.SWITCHING_SCENE = false;
483515
}
484516
}
485517
break;
@@ -494,5 +526,13 @@ private void AllowSceneActivation()
494526
// load the scene if is ready
495527
mAsyncOperation.allowSceneActivation = true;
496528
}
529+
530+
/// <summary>
531+
/// Return true if we are still in the entering switch scene state.
532+
/// </summary>
533+
private bool IsEnteringSwitchScene()
534+
{
535+
return mAsyncOperation != null && !mAsyncOperation.allowSceneActivation;
536+
}
497537
}
498538
}

Assets/JCSUnity/Scripts/UI/System/JCS_BlackScreen.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,16 @@ public void FadeOut(float time)
5858
}
5959

6060
/// <summary>
61-
/// Is the black screen fade in?
61+
/// Return true if the black screen is fade in.
6262
/// </summary>
63-
/// <returns></returns>
6463
public bool IsFadeIn()
6564
{
6665
return mFadeObject.IsFadeIn();
6766
}
6867

6968
/// <summary>
70-
/// Is the black screen fade out?
69+
/// Return true if the black screen is fade out.
7170
/// </summary>
72-
/// <returns></returns>
7371
public bool IsFadeOut()
7472
{
7573
return mFadeObject.IsFadeOut();

0 commit comments

Comments
 (0)