Пример #1
0
        /// <summary>
        /// 生成任务。
        /// </summary>
        /// <typeparam name="T">任务的类型。</typeparam>
        /// <param name="priority">任务的优先级。</param>
        /// <returns>生成的指定类型的任务。</returns>
        public T GenerateTask <T>(int priority) where T : TaskBase, new()
        {
            T task = ReferencePool.Acquire <T>();

            task.Initialize(++m_Serial, priority);
            task.OnGenerate();

            LinkedListNode <TaskBase> current = m_Tasks.First;

            while (current != null)
            {
                if (task.Priority > current.Value.Priority)
                {
                    break;
                }

                current = current.Next;
            }

            if (current != null)
            {
                m_Tasks.AddBefore(current, task);
            }
            else
            {
                m_Tasks.AddLast(task);
            }

            return(task);
        }
Пример #2
0
        public void AddLoadAssetInfo(string assetName, Type assetType, int priority, LoadAssetCallbacks loadAssetCallbacks, object userData)
        {
            if (loadAssetCallbacks == null)
            {
                Log.Error("Load asset callbacks is invalid.");
                return;
            }

            if (string.IsNullOrEmpty(assetName))
            {
                if (loadAssetCallbacks.AsyncAction != null)
                {
                    loadAssetCallbacks.CreateCallbackFailed(assetName, LoadResourceStatus.NotExist, "Asset name is invalid.", userData);

                    loadAssetCallbacks.AsyncAction.Invoke(loadAssetCallbacks);
                }
                else
                {
                    loadAssetCallbacks.LoadAssetFailureCallback?.Invoke(assetName, LoadResourceStatus.NotExist, "Asset name is invalid.", userData);
                }

                return;
            }

            m_LoadAssetInfos.AddLast(new LoadAssetInfo(assetName, assetType, priority, DateTime.Now, 0, loadAssetCallbacks, userData));
        }
Пример #3
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));
        }
Пример #4
0
        public void RecordDownloadedLength(int downloadedLength)
        {
            if (downloadedLength <= 0)
            {
                return;
            }

            if (m_DownloadCounterNodes.Count > 0)
            {
                DownloadCounterNode downloadCounterNode = m_DownloadCounterNodes.Last.Value;
                if (downloadCounterNode.ElapseSeconds < m_UpdateInterval)
                {
                    downloadCounterNode.AddDownloadedLength(downloadedLength);
                    return;
                }
            }

            m_DownloadCounterNodes.AddLast(DownloadCounterNode.Create(downloadedLength));
        }
Пример #5
0
        public void AddUnloadSceneInfo(string sceneAssetName, UnloadSceneCallbacks unloadSceneCallbacks, object userData)
        {
            if (string.IsNullOrEmpty(sceneAssetName))
            {
                Log.Error("Scene asset name is invalid.");
                return;
            }

            if (unloadSceneCallbacks == null)
            {
                Log.Error("Unload scene callbacks is invalid.");
                return;
            }

            AsyncOperation asyncOperation = SceneManager.UnloadSceneAsync(sceneAssetName);

            if (asyncOperation == null)
            {
                return;
            }

            m_UnloadSceneInfos.AddLast(new UnloadSceneInfo(asyncOperation, sceneAssetName, unloadSceneCallbacks, userData));
        }