Exemple #1
0
        public async UniTask ReturnAsync()
        {
            await _transition.FadeInAsync(_transitionDuration / 2f);

            if (_currentScreen != null)
            {
                _currentScreen.Hide();
            }

            _currentScreen = null;

            await _transition.FadeOutAsync(_transitionDuration / 2f);
        }
Exemple #2
0
        /// <summary>
        /// Loads a scene that contains a manager asynchronously.
        /// </summary>
        /// <param name="scene">The scene to be loaded.</param>
        /// <typeparam name="TManager">The type of the manager to be fetched in the scene.</typeparam>
        /// <returns>A task to be awaited which represents the loading. Its value is the scene's manager. </returns>
        /// <exception cref="Exception">Thrown if the given <paramref name="scene"/> does not contain a manager of type
        /// <typeparamref name="TManager"/>.</exception>
        private async UniTask <TManager> LoadManagedSceneAsync <TManager>(SceneReference scene)
            where TManager : MonoBehaviour
        {
            _loading = true;
            await _transition.FadeInAsync(TransitionDuration);

            if (_scene != null)
            {
                await SceneManager.UnloadSceneAsync(_scene.Value);
            }
            await SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);

            _scene = SceneManager.GetSceneByPath(scene);
            if (_scene == null)
            {
                throw new Exception($"Managed scene wasn't loaded ({typeof(TManager)}).");
            }

            SceneManager.SetActiveScene(_scene.Value);
            var manager = FindObjectOfType <TManager>();
            await _transition.FadeOutAsync(TransitionDuration);

            _loading = false;

            return(manager);
        }