private void Next(string sceneName, object transData, TransMode transMode)
        {
            if (IsLoading)
            {
                Debug.unityLogger.LogWarning(GetType().Name, "Loading");
                return;
            }

            if (_histories.Count > 0 && _histories.Peek().SceneName == sceneName)
            {
                Reload();
                return;
            }

            IsLoading = true;

            _histories.Push(new History()
            {
                SceneName = sceneName, TransData = transData
            });
            var nextContext = new LoadContext(sceneName, transData, transMode);

            StartCoroutine(Load(nextContext, _loadContext));
            _loadContext = nextContext;
        }
        private static IEnumerator LoadSubsInternal(LoadContext context, LoadContext prev)
        {
            yield return(context.AdditiveScenes
                         .Where(x => {
                if (prev == null)
                {
                    return true;
                }
                var cache = prev.AdditiveScenes.FirstOrDefault(y => x.Name == y.Name);
                if (cache == null)
                {
                    return true;
                }
                else
                {
                    x.Lifecycles = cache.Lifecycles;
                }
                return false;
            })
                         .Select(additiveScene => UnitySceneManager.LoadSceneAsync(additiveScene.Name, LoadSceneMode.Additive)
                                 .AsObservable()
                                 .Select(_ => FindSceneContext(additiveScene.Name))
                                 .SelectMany(x => new WaitUntil(() => x.Initialized)
                                             .ToObservable()
                                             .Select(_ => x))
                                 .Do(x => additiveScene.Lifecycles = x.Container.ResolveAll <ISceneLifecycle>().Where(y => !context.NextScene.Lifecycles.Any(z => y == z)))
                                 .FirstOrDefault())
                         .WhenAll()
                         .StartAsCoroutine());

            Resources.UnloadUnusedAssets();

            GC.Collect();
        }
        private static IEnumerator LoadInternal(LoadContext context)
        {
            if (context == null)
            {
                yield break;
            }

            var scene = UnitySceneManager.GetSceneByName(context.NextScene.Name);

            if (!scene.isLoaded)
            {
                yield return(UnitySceneManager.LoadSceneAsync(context.NextScene.Name, LoadSceneMode.Additive));
            }
            UnitySceneManager.SetActiveScene(UnitySceneManager.GetSceneByName(context.NextScene.Name));

            var sceneContext = FindSceneContext(context.NextScene.Name);

            if (sceneContext == null)
            {
                yield break;
            }

            yield return(new WaitUntil(() => sceneContext.Initialized));

            var sceneSettings = sceneContext.Container.TryResolve <SceneSettings>();

            if (sceneSettings != null)
            {
                sceneSettings.Subs.ForEach(x => context.AddAdditiveScene(x));
            }
            context.NextScene.Lifecycles = sceneContext.Container.ResolveAll <ISceneLifecycle>();
        }
        private IEnumerator Load(LoadContext next, LoadContext prev)
        {
            _eventSystem.enabled = false;
            if (prev != null)
            {
                yield return(prev.TransOut(next));
            }
            yield return(_transController.TransIn(next.TransMode));

            yield return(LoadInternal(next));

            if (prev != null)
            {
                yield return(prev.Unload(next));
            }
            if (prev != null)
            {
                yield return(UnloadInternal(prev, next));
            }
            yield return(LoadSubsInternal(next, prev));

            yield return(next.Load(prev));

            yield return(_transController.TransOut());

            yield return(next.TransIn(prev));

            next.TransComplete();
            IsLoading            = false;
            _eventSystem.enabled = true;
        }
Esempio n. 5
0
 public async UniTask TransOut(LoadContext next)
 {
     await AdditiveScenes
     .Where(x => next == null || !next.AdditiveScenes.Any(y => x.Name == y.Name))
     .SelectMany(x => x.Lifecycles)
     .Select(x => x.OnTransOut())
     .Concat(NextScene.Lifecycles
             .Select(x => x.OnTransOut()));
 }
Esempio n. 6
0
 public async UniTask TransIn(LoadContext prev)
 {
     await NextScene.Lifecycles
     .Select(x => x.OnTransIn())
     .Concat(AdditiveScenes
             .Where(x => prev == null || !prev.AdditiveScenes.Any(y => x.Name == y.Name))
             .SelectMany(x => x.Lifecycles)
             .Select(x => x.OnTransIn()));
 }
        private static IEnumerator UnloadInternal(LoadContext context, LoadContext next)
        {
            if (context == null)
            {
                yield break;
            }

            yield return(context.AdditiveScenes
                         .Where(x => next == null || !next.AdditiveScenes.Any(y => x.Name == y.Name))
                         .Select(x => UnitySceneManager.UnloadSceneAsync(x.Name)
                                 .ObserveEveryValueChanged(y => y.isDone)
                                 .FirstOrDefault())
                         .WhenAll()
                         .StartAsCoroutine());

            yield return(UnitySceneManager.UnloadSceneAsync(context.NextScene.Name));
        }
        private IEnumerator Reload(LoadContext context)
        {
            _eventSystem.enabled = false;
            yield return(context.TransOut());

            yield return(_transController.TransIn(context.TransMode));

            yield return(context.Unload());

            yield return(context.Load());

            yield return(_transController.TransOut());

            yield return(context.TransIn());

            context.TransComplete();
            IsLoading            = false;
            _eventSystem.enabled = true;
        }
        private void Back()
        {
            if (IsLoading)
            {
                Debug.unityLogger.LogWarning(GetType().Name, "Loading");
                return;
            }

            if (_histories.Count < 2)
            {
                Debug.unityLogger.LogWarning(GetType().Name, "Empty history");
                return;
            }

            _histories.Pop();
            var history     = _histories.Peek();
            var nextContext = new LoadContext(history.SceneName, history.TransData, TransMode.None);

            StartCoroutine(Load(nextContext, _loadContext));
            _loadContext = nextContext;
        }