Esempio n. 1
0
        private IEnumerator Load(LoadContext next, LoadContext prev)
        {
            if (prev != null)
            {
                yield return(prev.TransOut(next).StartAsCoroutine());
            }
            yield return(_transController.TransIn(next.TransMode));

            yield return(LoadInternal(next));

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

            yield return(next.Load(prev).StartAsCoroutine());

            yield return(_transController.TransOut());

            yield return(next.TransIn(prev).StartAsCoroutine());

            next.TransComplate();
            IsLoading = false;
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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>();
        }
Esempio n. 4
0
 public IObservable <Unit> TransOut(LoadContext next)
 {
     return(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()))
            .WhenAll());
 }
Esempio n. 5
0
 public IObservable <Unit> TransIn(LoadContext prev)
 {
     return(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()))
            .WhenAll());
 }
Esempio n. 6
0
        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));
        }
Esempio n. 7
0
        private void Next(string sceneName, object transData, TransMode transMode)
        {
            if (IsLoading)
            {
                Debug.unityLogger.LogWarning(GetType().Name, "Loading");
                return;
            }
            IsLoading = true;

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

            StartCoroutine(Load(nextContext, _loadContext));
            _loadContext = nextContext;
        }
Esempio n. 8
0
        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;
        }