77 * Copyright (c) 2016 by Shen, Jen-Chieh $
88 */
99using System ;
10- using System . IO ;
1110using System . Collections . Generic ;
11+ using System . IO ;
1212using UnityEngine ;
1313using UnityEngine . SceneManagement ;
14+ using UnityEngine . UI ;
1415using UnityEngine . Video ;
1516using MyBox ;
16- using UnityEngine . UI ;
1717
1818namespace JCSUnity
1919{
@@ -29,8 +29,7 @@ public class JCS_SceneManager : JCS_Manager<JCS_SceneManager>
2929 public Func < bool > onSwitchSceneIn = null ;
3030 public Func < bool > onSwitchSceneOut = null ;
3131
32- // Async loading scene operation. (thread)
33- private AsyncOperation mAsyncOperation = null ;
32+ private bool mIsEnteringSwitchScene = false ;
3433
3534 [ Separator ( "Check Variables (JCS_SceneManager)" ) ]
3635
@@ -261,7 +260,7 @@ private void Start()
261260
262261 private void Update ( )
263262 {
264- if ( IsEnteringSwitchScene ( ) )
263+ if ( mIsEnteringSwitchScene )
265264 DoEnterSwitchScene ( ) ;
266265 else
267266 DoExitSwitchScene ( ) ;
@@ -381,9 +380,8 @@ public void LoadScene(string sceneName, LoadSceneMode mode,
381380 apps . onSaveAppData ? . Invoke ( ) ;
382381 }
383382
384- // preload the scene
385- mAsyncOperation = SceneManager . LoadSceneAsync ( scs . nextSceneName , mode ) ;
386- mAsyncOperation . allowSceneActivation = false ;
383+ // Mark loading scene.
384+ mIsEnteringSwitchScene = true ;
387385
388386 switch ( mSwitchSceneType )
389387 {
@@ -600,30 +598,30 @@ private void DoEnterSwitchScene()
600598 if ( onSwitchSceneIn != null )
601599 {
602600 if ( onSwitchSceneIn . Invoke ( ) )
603- AllowSceneActivation ( ) ;
601+ EnterNextScene ( ) ;
604602 }
605603 }
606604 break ;
607605
608606 case JCS_SwitchSceneType . FADE :
609607 {
610608 if ( mBlackScreen . IsFadeIn ( ) )
611- AllowSceneActivation ( ) ;
609+ EnterNextScene ( ) ;
612610 }
613611 break ;
614612
615613 case JCS_SwitchSceneType . SLIDE :
616614 {
617615 if ( mBlackSlideScreen . IsDoneSliding ( ) )
618- AllowSceneActivation ( ) ;
616+ EnterNextScene ( ) ;
619617 }
620618 break ;
621619
622620 case JCS_SwitchSceneType . VIDEO :
623621 {
624622 if ( ! ss . videoPlayer . isPlaying )
625623 {
626- AllowSceneActivation ( ) ;
624+ EnterNextScene ( ) ;
627625
628626 ss . videoPlayer . enabled = false ;
629627 }
@@ -678,18 +676,17 @@ private void DoExitSwitchScene()
678676 /// <summary>
679677 /// Activate the next scene when it's ready.
680678 /// </summary>
681- private void AllowSceneActivation ( )
679+ private void EnterNextScene ( )
682680 {
683- // load the scene if is ready
684- mAsyncOperation . allowSceneActivation = true ;
681+ // Delay a bit of time to make sure it's completely
682+ // fade out.
683+ Invoke ( nameof ( InvokeEnterNextScene ) , 0.01f ) ;
685684 }
686-
687- /// <summary>
688- /// Return true if we are still in the entering switch scene state.
689- /// </summary>
690- private bool IsEnteringSwitchScene ( )
685+ private void InvokeEnterNextScene ( )
691686 {
692- return mAsyncOperation != null && ! mAsyncOperation . allowSceneActivation ;
687+ var scs = JCS_SceneSettings . FirstInstance ( ) ;
688+
689+ SceneManager . LoadScene ( scs . nextSceneName , scs . mode ) ;
693690 }
694691 }
695692}
0 commit comments