Exemplo n.º 1
0
        public void AddLoadSceneInfo(string sceneAssetName, int priority, LoadSceneCallbacks loadSceneCallbacks, object userData)
        {
            if (loadSceneCallbacks == null)
            {
                Log.Error("Load scene callbacks is invalid.");
                return;
            }

            if (string.IsNullOrEmpty(sceneAssetName))
            {
                if (loadSceneCallbacks.AsyncAction != null)
                {
                    loadSceneCallbacks.ErrorMessage = "Scene asset name is invalid.";

                    loadSceneCallbacks.AsyncAction.Invoke(loadSceneCallbacks);
                }
                else
                {
                    loadSceneCallbacks.LoadSceneFailureCallback?.Invoke(sceneAssetName, LoadResourceStatus.NotExist, "Scene asset name is invalid.", userData);
                }

                return;
            }

            AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneAssetName, LoadSceneMode.Additive);

            if (asyncOperation == null)
            {
                return;
            }

            m_LoadSceneInfos.AddLast(new LoadSceneInfo(asyncOperation, sceneAssetName, priority, DateTime.Now, loadSceneCallbacks, userData));
        }
Exemplo n.º 2
0
 public LoadSceneInfo(AsyncOperation asyncOperation, string sceneAssetName, int priority, DateTime startTime, LoadSceneCallbacks loadSceneCallbacks, object userData)
 {
     m_AsyncOperation     = asyncOperation;
     m_SceneAssetName     = sceneAssetName;
     m_Priority           = priority;
     m_StartTime          = startTime;
     m_LoadSceneCallbacks = loadSceneCallbacks;
     m_UserData           = userData;
 }
Exemplo n.º 3
0
 public LoadSceneTask()
 {
     m_LoadSceneCallbacks = null;
 }
Exemplo n.º 4
0
 public override void Clear()
 {
     base.Clear();
     m_LoadSceneCallbacks = null;
 }
Exemplo n.º 5
0
        public static LoadSceneTask Create(string sceneAssetName, AssetCategory assetCategory, int priority, ResourceInfo resourceInfo, Dictionary <string, AssetCategory> dependencyAssetNames, LoadSceneCallbacks loadSceneCallbacks, object userData)
        {
            LoadSceneTask loadSceneTask = ReferencePool.Acquire <LoadSceneTask>();

            loadSceneTask.Initialize(sceneAssetName, assetCategory, null, priority, resourceInfo, dependencyAssetNames, userData);
            loadSceneTask.m_LoadSceneCallbacks = loadSceneCallbacks;
            return(loadSceneTask);
        }
        /// <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);
            }
        }