Exemple #1
0
 /// <summary>
 /// 卸载场景。
 /// </summary>
 /// <param name="sceneAssetName">场景资源名称。</param>
 /// <param name="unloadSceneCallbacks">卸载场景回调函数集。</param>
 /// <param name="userData">用户自定义数据。</param>
 public override void UnloadScene(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
 {
     if (gameObject.activeInHierarchy)
     {
         StartCoroutine(UnloadSceneCo(sceneAssetName, unloadSceneCallbacks, userData));
     }
     else
     {
         SceneManager.UnloadSceneAsync(MonoScene.GetSceneName(sceneAssetName));
     }
 }
Exemple #2
0
        private IEnumerator UnloadSceneCo(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
        {
            AsyncOperation asyncOperation = SceneManager.UnloadSceneAsync(MonoScene.GetSceneName(sceneAssetName));

            if (asyncOperation == null)
            {
                yield break;
            }

            yield return(asyncOperation);

            if (asyncOperation.allowSceneActivation)
            {
                unloadSceneCallbacks.UnloadSceneSuccessCallback?.Invoke(sceneAssetName, userData);
            }
            else
            {
                unloadSceneCallbacks.UnloadSceneFailureCallback?.Invoke(sceneAssetName, userData);
            }
        }