/// <summary>
        /// 异步加载场景。
        /// </summary>
        /// <param name="sceneAssetName">要加载场景资源的名称。</param>
        /// <param name="priority">加载场景资源的优先级。</param>
        /// <param name="loadSceneCallbacks">加载场景回调函数集。</param>
        /// <param name="userData">用户自定义数据。</param>
        public void LoadScene(string sceneAssetName, AssetCategory assetCategory, int priority, LoadSceneCallbacks loadSceneCallbacks, object userData)
        {
            ResourceInfo resourceInfo = null;
            Dictionary <string, AssetCategory> dependencyAssetNames = null;

            if (!CheckAsset(sceneAssetName, assetCategory, out resourceInfo, out dependencyAssetNames))
            {
                string errorMessage = Utility.Text.Format("Can not load scene '{0}'.", sceneAssetName);
                if (loadSceneCallbacks.LoadSceneFailureCallback != null)
                {
                    loadSceneCallbacks.LoadSceneFailureCallback(sceneAssetName, resourceInfo != null && !resourceInfo.Ready ? LoadResourceStatus.NotReady : LoadResourceStatus.NotExist, errorMessage, userData);
                    return;
                }

                throw new Exception(errorMessage);
            }

            if (resourceInfo.IsLoadFromBinary)
            {
                string errorMessage = Utility.Text.Format("Can not load scene asset '{0}' which is a binary asset.", sceneAssetName);
                if (loadSceneCallbacks.LoadSceneFailureCallback != null)
                {
                    loadSceneCallbacks.LoadSceneFailureCallback(sceneAssetName, LoadResourceStatus.TypeError, errorMessage, userData);
                    return;
                }

                throw new Exception(errorMessage);
            }

            LoadSceneTask mainTask = LoadSceneTask.Create(sceneAssetName, assetCategory, priority, resourceInfo, dependencyAssetNames, loadSceneCallbacks, userData);

            foreach (var item in dependencyAssetNames)
            {
                if (!LoadDependencyAsset(item.Key, item.Value, priority, mainTask, userData))
                {
                    string errorMessage = Utility.Text.Format("Can not load dependency asset '{0}' when load scene '{1}'.", item.Key, sceneAssetName);
                    if (loadSceneCallbacks.LoadSceneFailureCallback != null)
                    {
                        loadSceneCallbacks.LoadSceneFailureCallback(sceneAssetName, LoadResourceStatus.DependencyError, errorMessage, userData);
                        return;
                    }

                    throw new Exception(errorMessage);
                }
            }

            m_TaskPool.AddTask(mainTask);
            if (!resourceInfo.Ready)
            {
                m_ResourceComponent.UpdateResource(resourceInfo.ResourceName);
            }
        }
Example #2
0
 public override void OnLoadAssetFailure(LoadResourceAgent agent, LoadResourceStatus status, string errorMessage)
 {
     base.OnLoadAssetFailure(agent, status, errorMessage);
     if (m_LoadSceneCallbacks.LoadSceneFailureCallback != null)
     {
         m_LoadSceneCallbacks.LoadSceneFailureCallback(AssetName, status, errorMessage, UserData);
     }
 }