/// <summary> /// 异步加载场景。 /// </summary> /// <param name="sceneAssetName">要加载场景资源的名称。</param> /// <param name="loadSceneCallbacks">加载场景回调函数集。</param> public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks) { if (string.IsNullOrEmpty(sceneAssetName)) { throw new AshException("Scene asset name is invalid."); } if (loadSceneCallbacks == null) { throw new AshException("Load scene callbacks is invalid."); } m_ResourceLoader.LoadScene(sceneAssetName, loadSceneCallbacks, null); }
/// <summary> /// 异步加载场景。 /// </summary> /// <param name="sceneAssetName">要加载场景资源的名称。</param> /// <param name="loadSceneCallbacks">加载场景回调函数集。</param> /// <param name="userData">用户自定义数据。</param> public void LoadScene(string sceneAssetName, LoadSceneCallbacks loadSceneCallbacks, object userData) { ResourceInfo?resourceInfo = null; string[] dependencyAssetNames = null; string[] scatteredDependencyAssetNames = null; string resourceChildName = null; if (!CheckAsset(sceneAssetName, out resourceInfo, out dependencyAssetNames, out scatteredDependencyAssetNames, out resourceChildName)) { string errorMessage = string.Format("Can not load scene '{0}'.", sceneAssetName); if (loadSceneCallbacks.LoadSceneFailureCallback != null) { loadSceneCallbacks.LoadSceneFailureCallback(sceneAssetName, LoadResourceStatus.NotReady, errorMessage, userData); return; } throw new AshException(errorMessage); } LoadSceneTask mainTask = new LoadSceneTask(sceneAssetName, resourceInfo.Value, dependencyAssetNames, scatteredDependencyAssetNames, resourceChildName, loadSceneCallbacks, userData); foreach (string dependencyAssetName in dependencyAssetNames) { if (!LoadDependencyAsset(dependencyAssetName, mainTask, userData)) { string errorMessage = string.Format("Can not load dependency asset '{0}' when load scene '{1}'.", dependencyAssetName, sceneAssetName); if (loadSceneCallbacks.LoadSceneFailureCallback != null) { loadSceneCallbacks.LoadSceneFailureCallback(sceneAssetName, LoadResourceStatus.DependencyError, errorMessage, userData); return; } throw new AshException(errorMessage); } } m_TaskPool.AddTask(mainTask); }