@@ -19,14 +19,16 @@ public class JCS_SceneManager : JCS_Manager<JCS_SceneManager>
1919 {
2020 /* Variables */
2121
22- private bool mSwitchSceneEffect = false ;
23- private string mNextSceneName = "" ;
24-
2522 // Async loading scene operation. (thread)
2623 private AsyncOperation mAsyncOperation = null ;
2724
2825 [ Separator ( "Check Variables (JCS_SceneManager)" ) ]
2926
27+ [ Tooltip ( "Next scene name to load." ) ]
28+ [ SerializeField ]
29+ [ ReadOnly ]
30+ private string mNextSceneName = "" ;
31+
3032 [ Tooltip ( "Black screen object to be assigned by the system." ) ]
3133 [ SerializeField ]
3234 [ ReadOnly ]
@@ -76,7 +78,7 @@ public class JCS_SceneManager : JCS_Manager<JCS_SceneManager>
7678 private float mSceneFadeOutTime = 1.0f ;
7779
7880 // fade the sound while switching the scene.
79- private JCS_FadeSound mJCSFadeSound = null ;
81+ private JCS_FadeSound mFadeSound = null ;
8082
8183 // Scene in the game so is dynamic instead of Unity's scene system's scene
8284 // Unity 自帶就有Scene這個物件. 在這個Unity Scene裡面自己宣告Scene
@@ -164,15 +166,15 @@ private void Start()
164166 if ( soundS . SMOOTH_SWITCH_SOUND_BETWEEN_SCENE )
165167 {
166168 // get the component.
167- if ( mJCSFadeSound == null )
168- mJCSFadeSound = this . gameObject . AddComponent < JCS_FadeSound > ( ) ;
169+ if ( mFadeSound == null )
170+ mFadeSound = this . gameObject . AddComponent < JCS_FadeSound > ( ) ;
169171
170172 // set the background audio source.
171- mJCSFadeSound . SetAudioSource (
173+ mFadeSound . SetAudioSource (
172174 soundM . GetBGMAudioSource ( ) ) ;
173175
174176 // active the fade sound in effect.
175- mJCSFadeSound . FadeIn (
177+ mFadeSound . FadeIn (
176178 soundS . GetBGM_Volume ( ) ,
177179 /* Fade in the sound base on the setting. */
178180 soundS . GetSoundFadeInTimeBaseOnSetting ( ) ) ;
@@ -302,8 +304,10 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
302304 }
303305#endif
304306
307+ var scenes = JCS_SceneSettings . instance ;
308+
305309 // if is loading already, dont load it agian
306- if ( mSwitchSceneEffect )
310+ if ( scenes . SWITCHING_SCENE )
307311 return ;
308312
309313 // set the next scene name
@@ -363,18 +367,18 @@ public void LoadScene(string sceneName, float fadeInTime, Color screenColor, boo
363367 if ( ss . SMOOTH_SWITCH_SOUND_BETWEEN_SCENE )
364368 {
365369 // get the component.
366- if ( mJCSFadeSound == null )
367- mJCSFadeSound = this . gameObject . AddComponent < JCS_FadeSound > ( ) ;
370+ if ( mFadeSound == null )
371+ mFadeSound = this . gameObject . AddComponent < JCS_FadeSound > ( ) ;
368372
369- mJCSFadeSound . SetAudioSource ( JCS_SoundManager . instance . GetBGMAudioSource ( ) ) ;
373+ mFadeSound . SetAudioSource ( JCS_SoundManager . instance . GetBGMAudioSource ( ) ) ;
370374
371375 // fade out sound to zero
372- mJCSFadeSound . FadeOut ( 0 , fadeInTime ) ;
376+ mFadeSound . FadeOut ( 0 , fadeInTime ) ;
373377 }
374378 }
375379
376380 // start check to switch scene or not
377- mSwitchSceneEffect = true ;
381+ scenes . SWITCHING_SCENE = true ;
378382 }
379383
380384 /// <summary>
@@ -476,16 +480,18 @@ public void ReloadScene(float fadeInTime, Color screenColor, bool keepBGM)
476480 /// <returns> return result. </returns>
477481 public bool IsSwitchingScene ( )
478482 {
479- return this . mSwitchSceneEffect ;
483+ return JCS_SceneSettings . instance . SWITCHING_SCENE ;
480484 }
481485
482486 /// <summary>
483487 /// Do the async switch scene.
484488 /// </summary>
485489 private void DoSwitchScene ( )
486490 {
491+ var scenes = JCS_SceneSettings . instance ;
492+
487493 // check if during the switch scene?
488- if ( ! mSwitchSceneEffect )
494+ if ( ! scenes . SWITCHING_SCENE )
489495 return ;
490496
491497 switch ( mSwitchSceneType )
@@ -494,16 +500,16 @@ private void DoSwitchScene()
494500 {
495501 if ( mBlackScreen . IsFadeIn ( ) )
496502 {
497- // No need this anymore, since we have the
498- // to clean up everything before we load the scene.
499- // we need this boolean to check weather the event can
500- // spawn new "GameObject" when "OnDestroy" function was
501- // called in Unity.
502- //mSwitchSceneEffect = false;
503-
504503 // load the scene if is ready
505504 mAsyncOperation . allowSceneActivation = true ;
506505 }
506+
507+ bool inNewScene = ( mNextSceneName == "" ) ;
508+
509+ if ( inNewScene && mBlackScreen . IsFadeOut ( ) )
510+ {
511+ scenes . SWITCHING_SCENE = false ;
512+ }
507513 }
508514 break ;
509515
0 commit comments