Exemple #1
0
        public ITask GetAdditiveLoader(string sceneName, SceneTransition sceneTransition = null, IEnumerable <GameObject> removals = null)
        {
            if (sceneTransition == null)
            {
                sceneTransition = defaultSceneTransition;
            }

//FIXME: Implement Additive for non unity pro
#if UNITY_PRO_LICENSED
            ITask task = new AdditiveSceneLoaderTask(this, sceneName, additiveLoaderWatermark, sceneTransition, removals, additiveLoaderDelay);

            task.Done += result => {
                if (result.IsOk())
                {
                    Logger.LogDebug(LoggerModules.SceneManager, string.Format("loaded scene {0}", sceneName));
                    SceneLoaded(sceneName);
                }
            };

            return(task);
#else
            CoreLogger.LogWarning("Warning - attempting to additively load a scene without Unity Pro License - currently unsupported action");
            return(new SceneLoaderTask(this, sceneName, sceneTransition, null));
#endif
        }
 public AdditiveSceneLoaderTask(SceneManager sceneManager, string sceneName, float additiveLoaderWatermark, SceneTransition sceneTransition, IEnumerable <GameObject> removals, float delay)
 {
     _sceneManager            = sceneManager;
     _delay                   = delay;
     _sceneName               = sceneName;
     _additiveLoaderWatermark = additiveLoaderWatermark;
     _name            = string.Format("additive load scene {0}", sceneName);
     _sceneTransition = sceneTransition;
     _removals        = removals;
 }
        public ITask GetAdditiveLoader(string newScene, SceneTransition sceneTransition = null, IEnumerable <GameObject> removals = null)
        {
            AsyncOperation operation = Application.LoadLevelAdditiveAsync(newScene);

            operation.allowSceneActivation = false;
            operation.priority             = 0;
            ITask task = _taskFactory.FromAsyncOperation(operation);

            task.Name = string.Format("load scene {0}", newScene);
            return(task);
        }
        public SceneLoaderTask(SceneManager sceneManger, string sceneName, SceneTransition sceneTransition, IEnumerable <IEnumerableAction> preloadActions)
        {
            _sceneName       = sceneName;
            _sceneManager    = sceneManger;
            _sceneTransition = sceneTransition;
            _preloadActions  = preloadActions;

            GameApplication.Instance.ApplicationEvents.LevelLoaded += OnLevelLoaded;

            _name = string.Format("loading scene {0}", sceneName);
        }
Exemple #5
0
 public void UnhookTransition(SceneTransition transition)
 {
     if (transition == null)
     {
         return;
     }
     transition.StartTransitionOut -= OnTransitionOutStarted;
     transition.StartTransitionIn  -= OnTransitionInStarted;
     transition.EndTransitionOut   -= OnTransitionOutEnded;
     transition.EndTransitionIn    -= OnTransitionInEnded;
 }
        public void InjectTransition(SceneTransition transition, ISceneController sceneController)
        {
            GameObject newInstance = GameObject.Instantiate(transition.gameObject) as GameObject;
            IEnumerable <SceneTransition> sceneTransitions = newInstance.GetComponents <SceneTransition>();

            _sceneManager.HookTransition(sceneTransitions.FirstOrDefault());

            GameObject.DontDestroyOnLoad(newInstance);
            newInstance.transform.parent = sceneController.Transform;

            foreach (SceneTransition sceneTransition in sceneTransitions)
            {
                CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("\tinjecting effect {0}", sceneTransition.GetType().Name));
            }
        }
Exemple #7
0
        public ISceneLoaderTask GetLoader(string sceneName, SceneTransition sceneTransition = null, IEnumerable <IEnumerableAction> preloadActions = null)
        {
            if (sceneTransition == null)
            {
                sceneTransition = defaultSceneTransition;
            }

            ISceneLoaderTask task = new SceneLoaderTask(this, sceneName, sceneTransition, preloadActions);

            task.Done += result => {
                if (result.IsOk())
                {
                    CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("loaded scene {0}", sceneName));
                    SceneLoaded(sceneName);
                }
            };

            return(task);
        }
        override protected IEnumerator Controller()
        {
            ISceneLoaderTask pending = _sceneManager.PendingLoadTask;

            if (pending != null)
            {
                if (pending.SceneName == _sceneName)
                {
                    CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: pending request for the same scene ({1}); ending operation", _name, _sceneName));
                    InvokeDone(TaskEnding.Done);
                    yield break;
                }
            }

            CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("setting pending load to additive loader: {0}", _name));
            _sceneManager.PendingLoadTask = this;

            if (pending != null)
            {
                CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1}...", _name, pending.Name));
                yield return(GameApplication.Instance.CoroutineFactory.Wait(pending));

                CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1} done!", _name, pending.Name));
            }

            SceneTransition sceneTransition = null;

            if (_sceneTransition != null)
            {
                sceneTransition = _sceneTransition.gameObject.GetComponent <SceneTransition>();
                if (sceneTransition != null)
                {
                    GameObject newInstance = GameObject.Instantiate(_sceneTransition.gameObject) as GameObject;
                    GameObject.DontDestroyOnLoad(newInstance);

                    sceneTransition = newInstance.GetComponent <SceneTransition>();
                    Debugger.Assert(sceneTransition != null, "sceneTransition cannot be null!");
                    if (sceneTransition != null)
                    {
                        _sceneManager.HookTransition(sceneTransition);
                        GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.ExitSequence);


                        yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadeout));
                    }
                }
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("starting additive sync load of scene {0}", _sceneName));
            Application.LoadLevelAdditive(_sceneName);
            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("done additive load of scene {0}", _sceneName));

            HandleRemovals();

            if (sceneTransition != null)
            {
                sceneTransition.OnLevelWasLoaded(Application.loadedLevel);

                yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadein));
            }

            if (_sceneManager.PendingLoadTask == this)
            {
                CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("resetting pending load from {0} to null", _name));
                _sceneManager.PendingLoadTask = null;
            }

            InvokeDone(TaskEnding.Done);
        }
        override protected IEnumerator Controller()
        {
            ISceneLoaderTask pending = _sceneManager.PendingLoadTask;

            if (pending != null)
            {
                if (pending.SceneName == _sceneName)
                {
                    CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: pending request for the same scene ({1}); ending operation", _name, _sceneName));
                    InvokeDone(TaskEnding.Done);
                    yield break;
                }
            }

            CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("setting pending load to additive loader: {0}", _name));
            _sceneManager.PendingLoadTask = this;

            if (pending != null)
            {
                CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1}...", _name, pending.Name));
                yield return(GameApplication.Instance.CoroutineFactory.Wait(pending));

                CoreLogger.LogNotice(LoggerModules.SceneManager, string.Format("{0}: waiting on loader {1} done!", _name, pending.Name));
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("starting additive async load of scene {0}", _sceneName));
            _operation = Application.LoadLevelAdditiveAsync(_sceneName);
            _operation.allowSceneActivation = false;
            _operation.priority             = 0;

            while (_progress < _additiveLoaderWatermark)
            {
                if (_cancel)
                {
                    InvokeDone(TaskEnding.Cancelled);
                    yield break;
                }

                yield return(null);

                _lastProgress = _progress;
                _progress     = _operation.progress;

                if (_progress < _lastProgress)
                {
                    //time travel - this can happen if we came back from background
                    CoreLogger.LogNotice(LoggerModules.SceneManager, "time travel in scene loader - loading the next scene and calling done");
                }
            }

            _progress = 1;
            yield return(null);

            yield return(new WaitForSeconds(_delay));

            SceneTransition sceneTransition = null;

            if (_sceneTransition != null)
            {
                sceneTransition = _sceneTransition.gameObject.GetComponent <SceneTransition>();
                if (sceneTransition != null)
                {
                    GameObject newInstance = GameObject.Instantiate(_sceneTransition.gameObject) as GameObject;
                    GameObject.DontDestroyOnLoad(newInstance);

                    sceneTransition = newInstance.GetComponent <SceneTransition>();
                    Debugger.Assert(sceneTransition != null, "sceneTransition cannot be null!");
                    if (sceneTransition != null)
                    {
                        GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.ExitSequence);

                        yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadeout));
                    }
                }
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("allowing scene additive load operation to complete"));

            _operation.allowSceneActivation = true;
            yield return(_operation);

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("done additive load of scene {0}", _sceneName));

            HandleRemovals();

            if (sceneTransition != null)
            {
                sceneTransition.OnLevelWasLoaded(Application.loadedLevel);
                CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} will now handle transition {1}", _sceneName, sceneTransition.name));
                yield return(GameApplication.Instance.CoroutineFactory.StartCoroutine(sceneTransition.WaitForFadein));
            }

            if (_sceneManager.PendingLoadTask == this)
            {
                CoreLogger.LogDebug(LoggerModules.SceneManager, string.Format("resetting pending load from {0} to null", _name));
                _sceneManager.PendingLoadTask = null;
            }
            else
            {
                if (_sceneManager.PendingLoadTask == null)
                {
                    CoreLogger.LogError(LoggerModules.SceneManager, string.Format("{0}: pending load is null!", _name));
                }
                else
                {
                    CoreLogger.LogError(LoggerModules.SceneManager, string.Format("{0}: no need to reset pending since it is already somebody else: {1}", _name, _sceneManager.PendingLoadTask.Name));
                }
            }

            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} will now invoke done", _sceneName));
            InvokeDone(TaskEnding.Done);
            CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("additive load of scene {0} has invoked done", _sceneName));
        }
Exemple #10
0
 void OnTransitionInEnded(SceneTransition sceneTransition)
 {
     CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("scene manager received end transition in event"));
     TransitionInEnded(SceneController.Current == null ? "<unknown>" : SceneController.Current.SceneName);
     UnhookTransition(sceneTransition);
 }
Exemple #11
0
 void OnTransitionOutStarted(SceneTransition sceneTransition)
 {
     CoreLogger.LogInfo(LoggerModules.SceneManager, string.Format("scene manager received start transition out event"));
     TransitionOutStarted(SceneController.Current == null ? "<unknown>" : SceneController.Current.SceneName);
 }