/// <summary> /// 任务管理器轮询。 /// </summary> /// <param name="elapseSeconds">逻辑流逝时间,以秒为单位。</param> /// <param name="realElapseSeconds">真实流逝时间,以秒为单位。</param> public override void Update(float elapseSeconds, float realElapseSeconds) { base.Update(elapseSeconds, realElapseSeconds); LinkedListNode <TaskBase> current = m_Tasks.First; while (current != null) { TaskBase task = current.Value; if (task.Status == TaskStatus.Free) { throw new Exception("Task status is invalid."); } if (task.Status == TaskStatus.Waiting) { task.OnStart(); } if (task.Status == TaskStatus.Running) { task.OnUpdate(elapseSeconds, realElapseSeconds); current = current.Next; } else { LinkedListNode <TaskBase> next = current.Next; m_Tasks.Remove(current); ReferencePool.Release(task); current = next; } } }
public void UpdateSceneInfo() { if (m_LoadSceneInfos.Count > 0) { LinkedListNode <LoadSceneInfo> current = m_LoadSceneInfos.First; while (current != null) { LoadSceneInfo loadSceneInfo = current.Value; if (loadSceneInfo.AsyncOperation.isDone) { if (loadSceneInfo.AsyncOperation.allowSceneActivation) { loadSceneInfo.LoadSceneCallbacks.LoadSceneSuccessCallback?.Invoke(loadSceneInfo.SceneAssetName, (float)(DateTime.Now - loadSceneInfo.StartTime).TotalSeconds, loadSceneInfo.UserData); } else { loadSceneInfo.LoadSceneCallbacks.LoadSceneFailureCallback?.Invoke(loadSceneInfo.SceneAssetName, LoadResourceStatus.AssetError, "Can not load this scene from asset database.", loadSceneInfo.UserData); } LinkedListNode <LoadSceneInfo> next = current.Next; m_LoadSceneInfos.Remove(loadSceneInfo); current = next; } else { loadSceneInfo.LoadSceneCallbacks.LoadSceneUpdateCallback?.Invoke(loadSceneInfo.SceneAssetName, loadSceneInfo.AsyncOperation.progress, loadSceneInfo.UserData); current = current.Next; } } } }
public void UpdateUnSceneInfo() { LinkedListNode <UnloadSceneInfo> current = m_UnloadSceneInfos.First; while (current != null) { UnloadSceneInfo unloadSceneInfo = current.Value; if (unloadSceneInfo.AsyncOperation.isDone) { if (unloadSceneInfo.AsyncOperation.allowSceneActivation) { unloadSceneInfo.UnloadSceneCallbacks.UnloadSceneSuccessCallback?.Invoke(unloadSceneInfo.SceneAssetName, unloadSceneInfo.UserData); } else { unloadSceneInfo.UnloadSceneCallbacks.UnloadSceneFailureCallback?.Invoke(unloadSceneInfo.SceneAssetName, unloadSceneInfo.UserData); } LinkedListNode <UnloadSceneInfo> next = current.Next; m_UnloadSceneInfos.Remove(unloadSceneInfo); current = next; } else { current = current.Next; } } }
public void UpdateAssetInfo() { if (m_LoadAssetInfos.Count > 0) { int count = 0; LinkedListNode <LoadAssetInfo> current = m_LoadAssetInfos.First; while (current != null && count < 1) { LoadAssetInfo loadAssetInfo = current.Value; float elapseSeconds = (float)(DateTime.Now - loadAssetInfo.StartTime).TotalSeconds; if (elapseSeconds >= loadAssetInfo.DelaySeconds) { UnityEngine.Object asset = null; #if UNITY_EDITOR if (loadAssetInfo.AssetType != null) { asset = UnityEditor.AssetDatabase.LoadAssetAtPath(loadAssetInfo.AssetName, loadAssetInfo.AssetType); } else { asset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(loadAssetInfo.AssetName); } #endif if (asset != null) { if (loadAssetInfo.LoadAssetCallbacks.AsyncAction != null) { loadAssetInfo.LoadAssetCallbacks.CreateCallbackSuccess(loadAssetInfo.AssetName, asset, elapseSeconds, loadAssetInfo.UserData); loadAssetInfo.LoadAssetCallbacks.AsyncAction.Invoke(loadAssetInfo.LoadAssetCallbacks); } else { loadAssetInfo.LoadAssetCallbacks.LoadAssetSuccessCallback?.Invoke(loadAssetInfo.AssetName, asset, elapseSeconds, loadAssetInfo.UserData); } } else { if (loadAssetInfo.LoadAssetCallbacks.AsyncAction != null) { loadAssetInfo.LoadAssetCallbacks.CreateCallbackFailed(loadAssetInfo.AssetName, LoadResourceStatus.AssetError, "Can not load this asset from asset database.", loadAssetInfo.UserData); loadAssetInfo.LoadAssetCallbacks.AsyncAction.Invoke(loadAssetInfo.LoadAssetCallbacks); } else { loadAssetInfo.LoadAssetCallbacks.LoadAssetFailureCallback?.Invoke(loadAssetInfo.AssetName, LoadResourceStatus.AssetError, "Can not load this asset from asset database.", loadAssetInfo.UserData); } } LinkedListNode <LoadAssetInfo> next = current.Next; m_LoadAssetInfos.Remove(loadAssetInfo); current = next; count++; } else { loadAssetInfo.LoadAssetCallbacks.LoadAssetUpdateCallback?.Invoke(loadAssetInfo.AssetName, elapseSeconds / loadAssetInfo.DelaySeconds, loadAssetInfo.UserData); current = current.Next; } } } }