Beispiel #1
0
 public void LoadScene(string sceneName)
 {
     if (m_CurrentScenes.Contains(sceneName))
     {
         throw new DrbException("already exists scene '{0}'", sceneName);
     }
     m_Loader.LoadScene(sceneName);
 }
 public void Execute(LoadSceneSignal loadParams)
 {
     _sceneLoader.LoadScene(loadParams.Scene).Done(
         () =>
     {
         loadParams.OnComplete?.Resolve();
     },
         exception =>
     {
         loadParams.OnComplete?.Reject(exception);
     }
         );
 }
        //First loads an optional array of scenes, then
        //unloads a separate optional array of scenes.
        //Each call to load/unload is added into a
        //promise chain. When complete, the last promise
        //fires an optional OnComplete delegate.
        public void Execute(LoadUnloadScenesSignal loadUnloadParams)
        {
            IPromise lastPromise = null;

            //Load scenes
            if (loadUnloadParams.LoadScenes != null)
            {
                foreach (var sceneName in loadUnloadParams.LoadScenes)
                {
                    var name = sceneName;
                    lastPromise = lastPromise != null?lastPromise.Then(() => _sceneLoader.LoadScene(name)) : _sceneLoader.LoadScene(sceneName);
                }
            }

            //Unload scenes
            if (loadUnloadParams.UnloadScenes != null)
            {
                foreach (var sceneName in loadUnloadParams.UnloadScenes)
                {
                    var name = sceneName;
                    lastPromise = lastPromise != null?lastPromise.Then(() => _sceneLoader.UnloadScene(name)) : _sceneLoader.UnloadScene(sceneName);
                }
            }

            //Add promise to resolve OnComplete
            if (lastPromise != null)
            {
                lastPromise.Done(
                    () =>
                {
                    Debug.Log($"{this} , scene loading/unloading completed!");

                    loadUnloadParams.OnComplete?.Resolve();
                },
                    exception =>
                {
                    loadUnloadParams.OnComplete?.Reject(exception);
                }
                    );
            }
            else
            {
                Debug.Log($"{this} , no scenes loaded/unloaded!");

                loadUnloadParams.OnComplete?.Resolve();
            }
        }
Beispiel #4
0
        //First loads an optional array of scenes, then
        //unloads a separate optional array of scenes.
        //Each call to load/unload is added into a
        //promise chain. When complete, the last promise
        //fires an optional OnComplete delegate.
        public void Execute(LoadUnloadScenesSignal loadUnloadParams)
        {
            IPromise lastPromise = null;

            //Load scenes
            if (loadUnloadParams.LoadScenes != null)
            {
                for (int i = 0; i < loadUnloadParams.LoadScenes.Length; i++)
                {
                    string sceneName = loadUnloadParams.LoadScenes[i];
                    if (lastPromise != null)
                    {
                        lastPromise = lastPromise.Then(() => _sceneLoader.LoadScene(sceneName));
                    }
                    else
                    {
                        lastPromise = _sceneLoader.LoadScene(sceneName);
                    }
                }
            }

            //Unload scenes
            if (loadUnloadParams.UnloadScenes != null)
            {
                for (int i = 0; i < loadUnloadParams.UnloadScenes.Length; i++)
                {
                    string sceneName = loadUnloadParams.UnloadScenes[i];
                    if (lastPromise != null)
                    {
                        lastPromise = lastPromise.Then(() => _sceneLoader.UnloadScene(sceneName));
                    }
                    else
                    {
                        lastPromise = _sceneLoader.UnloadScene(sceneName);
                    }
                }
            }

            //Add promise to resolve OnComplete
            if (lastPromise != null)
            {
                lastPromise.Done(
                    () =>
                {
                    Debug.Log(string.Format("{0} , scene loading/unloading completed!", this));

                    loadUnloadParams.OnComplete?.Resolve();
                },
                    exception =>
                {
                    loadUnloadParams.OnComplete?.Reject(exception);
                }
                    );
            }
            else
            {
                Debug.Log(string.Format("{0} , no scenes loaded/unloaded!", this));

                loadUnloadParams.OnComplete?.Resolve();
            }
        }