コード例 #1
0
        public static AsyncOperationHandle <SceneInstance> UnloadSceneAsync(SceneInstance pScene, Action <float> pProgress = null, Action <bool> pOnCompleted = null)
        {
            var operation = Addressables.UnloadSceneAsync(pScene);

            WaitUnloadTask(operation, pProgress, pOnCompleted);
            return(operation);
        }
コード例 #2
0
        public void Unload(Action <AddressableSceneUnloaderResult> complete)
        {
            m_Complete = complete;
            var asyncOperationHandle = Addressables.UnloadSceneAsync(m_SceneInstance);

            asyncOperationHandle.Completed += AddressableSceneUnloaded;
        }
コード例 #3
0
        IEnumerator LoadScene(string sceneName)
        {
            Debug.Log($"[Client] <b>Loading level</b> '<i>{sceneName}</i>'");

            EventHub <StartedLoading> .Emit(new StartedLoading());

            // Cleanup
            currentReplicaPossess = ReplicaId.Invalid;

            Client.replicaManager.Reset();

            if (sceneHandle.IsValid())
            {
                yield return(Addressables.UnloadSceneAsync(sceneHandle));
            }

            // New map
#if !UNITY_EDITOR
            sceneHandle            = Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            sceneHandle.Completed += ctx => {
                SendLoadSceneDone();
                EventHub <EndedLoading> .Emit(new EndedLoading());
            };
#else
            SendLoadSceneDone();
            EventHub <EndedLoading> .Emit(new EndedLoading());
#endif
        }
コード例 #4
0
 public void OnExit()
 {
     if (StateSceneAsyncOperationHandle.IsDone)
     {
         Addressables.UnloadSceneAsync(StateSceneAsyncOperationHandle);
     }
 }
コード例 #5
0
    public static IPromise UnloadSceneAsync(SceneInstance scene)
    {
        string name    = scene.Scene.name;
        var    request = Addressables.UnloadSceneAsync(scene);

        return(WaitForRequest(request, "Unloaded addressable scene: " + name));
    }
コード例 #6
0
        /// <summary>
        /// Reset replication, instruct all clients to load the new scene, actually
        /// load the new scene on the server and finally create a new GameMode instance.
        /// </summary>
        /// <param name="sceneName"></param>
        public void LoadScene(string sceneName)
        {
            // Cleanup
            if (gameMode != null)
            {
                gameMode.StartToLeaveMap();
            }

            IsLoadingScene = true;
            ++loadSceneGeneration;
            numLoadScenePlayerAcks = 0;
            loadSceneName          = sceneName;

            server.ReplicaManager.Reset();
            if (sceneHandle.IsValid())
            {
                Addressables.UnloadSceneAsync(sceneHandle);
            }



            // Instruct clients
            var bs = new BitStream();

            bs.Write((byte)MessageId.LoadScene);
            bs.Write(sceneName);
            bs.Write(loadSceneGeneration);

            server.NetworkInterface.BroadcastBitStream(bs, PacketReliability.ReliableSequenced);

            // Disable ReplicaViews during level load
            foreach (var connection in server.connections)
            {
                var replicaView = server.ReplicaManager.GetReplicaView(connection);
                if (replicaView == null)
                {
                    continue;
                }

                replicaView.IsLoadingLevel = true;
            }

            // Load new map
            Debug.Log($"[Server] Loading level {sceneName}");
#if UNITY_EDITOR
            if (SceneManager.GetSceneByName(sceneName).isLoaded)
            {
                SceneManager.UnloadScene(sceneName);
            }
#endif
            sceneHandle            = Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
            sceneHandle.Completed += ctx => {
                IsLoadingScene = false;

                gameMode = CreateGameModeForScene(sceneName);
                Assert.IsNotNull(gameMode);

                Debug.Log($"[Server] New GameMode <i>{gameMode}</i>");
            };
        }
コード例 #7
0
 public void LoadAdresseableScene(string sceneName, bool unloadLastScene)
 {
     if (unloadLastScene)
     {
         Addressables.UnloadSceneAsync(handle, true);
     }
     Addressables.LoadSceneAsync(sceneName, LoadSceneMode.Additive, true).Completed += AdresseableSceneLoadComplete;
 }
コード例 #8
0
        public IPromise Unload()
        {
#if USE_ADDRESSABLES
            return(Addressables.UnloadSceneAsync(sceneInstance).GetPromiseWithoutResult());
#else
            return(SceneManager.UnloadSceneAsync(scene).GetPromise());
#endif
        }
コード例 #9
0
ファイル: AddressableAsync.cs プロジェクト: JCYTop/Project_X
        /// <summary>
        /// 卸载场景
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="completed"></param>
        /// <returns></returns>
        public static AsyncOperationHandle <SceneInstance> UnloadSceneAsync(SceneInstance sceneName,
                                                                            Action <AsyncOperationHandle <SceneInstance> > completed = null)
        {
            var operation = Addressables.UnloadSceneAsync(sceneName);

            operation.Completed += completed;
            return(operation);
        }
コード例 #10
0
ファイル: GameAsset.cs プロジェクト: lixiaobing/UnityBase
 public static void UnloadScene(string sceneName)
 {
     if (cacheScene.TryGetValue(sceneName, out SceneInstance scene))
     {
         cacheScene.Remove(sceneName);
         Addressables.UnloadSceneAsync(scene);
     }
 }
コード例 #11
0
        public void Start()
        {
            if (Handle.IsValid())
            {
                throw new InvalidOperationException();
            }

            Handle = Addressables.UnloadSceneAsync(_task.Handle);
        }
コード例 #12
0
 private void UnloadScene()
 {
     Addressables.UnloadSceneAsync(_loadedSceneHandle, true).Completed += op => {
         if (op.Status == AsyncOperationStatus.Succeeded)
         {
             Debug.Log("Successfully unloaded scene.");
         }
     };
 }
コード例 #13
0
 // Level scene unloading function.
 void UnloadLevel()
 {
     Addressables.UnloadSceneAsync(handle, true).Completed += op =>
     {
         if (op.Status == AsyncOperationStatus.Succeeded)
         {
             Debug.Log("Successfully unload " + currentLevel);
         }
     };
 }
コード例 #14
0
        public AsyncOperationHandle UnloadSceneAsync(AsyncOperationHandle <SceneInstance> sceneHandle)
        {
            var handle = Addressables.UnloadSceneAsync(sceneHandle).AddCompleteCallback(
                (result) =>
            {
            });

            //public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(AsyncOperationHandle<SceneInstance> handle, bool autoReleaseHandle = true);
            //public static AsyncOperationHandle<SceneInstance> UnloadSceneAsync(AsyncOperationHandle handle, bool autoReleaseHandle = true);
            return(handle);
        }
コード例 #15
0
 public void Dispose()
 {
     if (loadType == typeof(Scene))
     {
         Addressables.UnloadSceneAsync(loadHandle);
     }
     else
     {
         Addressables.Release(loadHandle);
     }
 }
コード例 #16
0
    /*
     * Summary:
     * Prepares to load the main menu scene, first removing the Gameplay scene in case the game is coming back from
     * gamplay to menus.
     *
     */
    private void LoadMenu(GameSceneSO[] menusToLoad, bool showLoadingScreen)
    {
        _scenesToLoad      = menusToLoad;
        _showLoadingScreen = showLoadingScreen;

        //In case we are coming from a location back to manin menu, we need to get rid of persistent Gameplay manager scene
        if (_gameplayManagerSceneInstance.Scene != null && _gameplayManagerSceneInstance.Scene.isLoaded)
        {
            Addressables.UnloadSceneAsync(_gameplayManagerLoadingOpHandle, true);
        }

        UnloadPreviousScenes();
    }
コード例 #17
0
        void OnDisconnected(string reason)
        {
            Debug.Log("[Client] <b>Disconnected</b> (" + reason + ")");

            // Cleanup
            currentReplicaPossess = ReplicaId.Invalid;

            Client.replicaManager.Reset();

            if (sceneHandle.IsValid())
            {
                Addressables.UnloadSceneAsync(sceneHandle);
            }
        }
コード例 #18
0
 public void UnloadSceneAsync(ResourceHandle handle, Action onFinish)
 {
     if (!handle.IsSceneObject)
     {
         Assert.IsTrue(false, "Unload() を呼んで下さい");
     }
     else
     {
         Addressables.UnloadSceneAsync(handle.HandleScene).Completed += op =>
         {
             onFinish?.Call();
         };
     }
 }
コード例 #19
0
ファイル: SceneController.cs プロジェクト: SuperKLA/Jamming
        protected override void OnEntityDestroy(IScene entity)
        {
            base.OnEntityDestroy(entity);

            if (this._sceneInstance.Scene.IsValid())
            {
                Addressables.UnloadSceneAsync(this._sceneInstance);
            }
            else
            {
                var isDone = SceneManager.UnloadSceneAsync(this._scene);
            }

            this._roots = null;
        }
コード例 #20
0
 private void UnloadScene()
 {
     Debug.Log("unloading level");
     Debug.Log(handle);
     Addressables.UnloadSceneAsync(handle, true).Completed += op =>
     {
         if (op.Status == AsyncOperationStatus.Succeeded)
         {
             Debug.Log("Successfully unloaded scene.");
         }
         else
         {
             Debug.Log(op.Status.ToString());
         }
     };
 }
コード例 #21
0
 public void onClickBtn(int sceneId)
 {
     if (sceneId == _loadingSceneId)
     {
         return;
     }
     _loadingSceneId = sceneId;
     if (_currentScene.Scene.isLoaded)
     {
         Addressables.UnloadSceneAsync(_currentScene).Completed += UnloadSceneCompleted;
     }
     else
     {
         LoadScene();
     }
 }
    IEnumerator Start()
    {
        yield return(Addressables.InitializeAsync());

        yield return(new WaitForSeconds(1));

        var asyncOperation = sceneReference.LoadSceneAsync(LoadSceneMode.Additive);

        yield return(asyncOperation);

        var scene = asyncOperation.Result;

        yield return(new WaitForSeconds(3));

        yield return(Addressables.UnloadSceneAsync(scene));
    }
コード例 #23
0
ファイル: GameManager.cs プロジェクト: ksgfk/Space-of-Lawless
        public async void UnloadWorld(Action callback = null)
        {
            if (!World.HasValue)
            {
                Debug.LogWarning("没有活动中世界");
                return;
            }

            var world = World.Value;

            world.Dispose();
            await Addressables.UnloadSceneAsync(world.Scene).Task;

            _world = null;
            callback?.Invoke();
        }
コード例 #24
0
 public void UnloadScene(SceneLookupEnum key)
 {
     if (m_scene.ContainsKey(key))
     {
         var scene = Addressables.UnloadSceneAsync(m_scene[key]);
         scene.Completed += (result) =>
         {
             if (result.Status == AsyncOperationStatus.Succeeded)
             {
                 m_scene.Remove(key);
             }
             else
             {
                 Debug.LogError($"场景======{key} 卸载失败!!!");
             }
         };
     }
 }
コード例 #25
0
        private static void UnLoadScene(string sceneName, Action callback)
        {
            if (!sceneDic.ContainsKey(sceneName))
            {
                Debug.LogWarning($"没有找到对应卸载场景的句柄:{sceneName}");
                return;
            }
            SceneInstance m_LoadedScene = sceneDic[sceneName].Result;

            Addressables.UnloadSceneAsync(m_LoadedScene).Completed += handle =>
            {
                if (handle.Status == AsyncOperationStatus.Succeeded)
                {
                    Addressables.Release(sceneDic[sceneName]);
                    sceneDic.Remove(sceneName);
                }
            };
        }
コード例 #26
0
    public void Unload()
    {
        if (!Loaded)
        {
            return;
        }

        if (_sceneInstance.HasValue)
        {
            Addressables.UnloadSceneAsync(_sceneInstance.Value);
            _sceneInstance = null;
        }
        else if (_scene.HasValue)
        {
            SceneManager.UnloadSceneAsync(_scene.Value, UnloadSceneOptions.None);
            _scene = null;
        }
    }
コード例 #27
0
 void OnButtonClick()
 {
     if (string.IsNullOrEmpty(addressToAdd))
     {
         Debug.LogError("Address To Add not set.");
     }
     else
     {
         if (m_ReadyToLoad)
         {
             Addressables.LoadSceneAsync(addressToAdd, LoadSceneMode.Additive).Completed += OnSceneLoaded;
         }
         else
         {
             Addressables.UnloadSceneAsync(m_LoadedScene).Completed += OnSceneUnloaded;
         }
     }
 }
コード例 #28
0
    /// <summary>
    /// Prepares to load the main menu scene, first removing the Gameplay scene in case the game is coming back from gameplay to menus.
    /// </summary>
    private void LoadMenu(GameSceneSO menuToLoad, bool showLoadingScreen, bool fadeScreen)
    {
        //Prevent a double-loading, for situations where the player falls in two Exit colliders in one frame
        if (_isLoading)
        {
            return;
        }

        _sceneToLoad       = menuToLoad;
        _showLoadingScreen = showLoadingScreen;
        _isLoading         = true;

        //In case we are coming from a Location back to the main menu, we need to get rid of the persistent Gameplay manager scene
        if (_gameplayManagerSceneInstance.Scene != null &&
            _gameplayManagerSceneInstance.Scene.isLoaded)
        {
            Addressables.UnloadSceneAsync(_gameplayManagerLoadingOpHandle, true);
        }

        StartCoroutine(UnloadPreviousScene());
    }
コード例 #29
0
        /// <summary>
        /// 卸载场景
        /// </summary>
        /// <param name="loadedScene"></param>
        /// <param name="onComplete"></param>
        /// <param name="onEnd"></param>
        /// <param name="userData"></param>
        /// <returns></returns>
        static async public void UnloadSceneAsync(SceneInstance loadedScene, System.Action <SceneInstance, object> onComplete, System.Action <SceneInstance, object> onEnd, object userData = null)
        {
            var   task = Addressables.UnloadSceneAsync(loadedScene).Task;
            await task;

            if (task.Status == System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                if (onComplete != null)
                {
                    onComplete(task.Result, userData);
                }
                string key = null;
                foreach (var kv in m_LoadedScenes)
                {
                    if (kv.Value.Equals(loadedScene))
                    {
                        key = kv.Key;
                        break;
                    }
                }

                if (key != null)
                {
                    m_LoadedScenes.Remove(key);
                }
            }
            else
            {
                if (onEnd != null)
                {
                    onEnd(loadedScene, userData);
                }
#if UNITY_EDITOR
                Debug.LogError("Failed to unload scene : " + loadedScene);
#endif
            }
        }
コード例 #30
0
ファイル: GameManager.cs プロジェクト: ksgfk/Space-of-Lawless
        private async void LoadWorld(EntryWorld worldEntry, Action callback = null)
        {
            if (World.HasValue)
            {
                Debug.LogWarning("有活动中世界");
                return;
            }

            if (worldEntry == null)
            {
                return;
            }

            var instance = await Addressables.LoadSceneAsync(worldEntry.AssetAddr, LoadSceneMode.Additive).Task;

            var c = instance.Scene.GetRootGameObjects().FirstOrDefault(go => go.CompareTag("WorldCenter"));

            if (c == null)
            {
                Addressables.UnloadSceneAsync(instance);
                Debug.LogWarning("不是标准世界");
                return;
            }

            if (c.TryGetComponent(out _world))
            {
                _world.Init(this, in instance);
                SceneManager.SetActiveScene(instance.Scene);
                callback?.Invoke();
            }
            else
            {
                Addressables.UnloadSceneAsync(instance);
                Debug.LogWarning("不是标准世界");
            }
        }