public void LoadScene(int sceneId) { if (m_CurrSceneIsLoading) { GameEntry.LogError("场景{0}正在加载中", m_CurrLoadSceneId); return; } if (m_CurrLoadSceneId == sceneId) { GameEntry.LogError("正在重复加载场景{0}", m_CurrLoadSceneId); return; } m_CurrLoadingParam = GameEntry.Pool.DequeueClassObject <BaseParams>(); //加载Loading GameEntry.UI.OpenUIForm(UIFormId.Loading, onOpen: (UIFormBase formBase) => { m_CurrProgress = 0; m_TargetProgressDic.Clear(); m_CurrSceneIsLoading = true; m_CurrLoadSceneId = sceneId; //先卸载当前场景 UnLoadCurrScene(); }); }
/// <summary> /// 根据资源分类和资源路径获取资源信息 /// </summary> /// <param name="assetCategory"></param> /// <param name="assetFullName"></param> /// <returns></returns> public AssetEntity GetAssetEntity(AssetCategory assetCategory, string assetFullName) { Dictionary <string, AssetEntity> dicCategory = null; if (m_AssetInfoDic.TryGetValue(assetCategory, out dicCategory)) { AssetEntity entity = null; if (dicCategory.TryGetValue(assetFullName, out entity)) { return(entity); } } GameEntry.LogError("assetFullName=>{0}不存在", assetFullName); return(null); }
/// <summary> /// 同时下载多个文件 /// </summary> /// <param name="lstUrl"></param> /// <param name="onDownloadMulitUpdate"></param> /// <param name="onDownloadMulitComplete"></param> public void BeginDownloadMulit(LinkedList <string> lstUrl, BaseAction <int, int, ulong, ulong> onDownloadMulitUpdate = null, BaseAction onDownloadMulitComplete = null) { m_OnDownloadMulitUpdate = onDownloadMulitUpdate; m_OnDownloadMulitComplete = onDownloadMulitComplete; m_NeedDownloadList.Clear(); m_DownloadMulitCurrSizeDic.Clear(); m_DownloadMulitNeedCount = 0; m_DownloadMulitCurrCount = 0; m_DownloadMulitTotalSize = 0; m_DownloadMulitCurrSize = 0; for (LinkedListNode <string> item = lstUrl.First; item != null; item = item.Next) { string url = item.Value; AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url); if (entity != null) { m_DownloadMulitTotalSize += entity.Size; m_DownloadMulitNeedCount++; m_NeedDownloadList.AddLast(url); m_DownloadMulitCurrSizeDic[url] = 0; } else { GameEntry.LogError("无效资源包=>" + url); } } int routineCount = Mathf.Min(GameEntry.Download.DownloadRoutineCount, m_NeedDownloadList.Count); for (int i = 0; i < routineCount; i++) { DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>(); string url = m_NeedDownloadList.First.Value; m_NeedDownloadList.RemoveFirst(); AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url); routine.BeginDownload(url, entity, OnDownloadMulitUpdate, OnDownloadMulitComplete); m_DownloadRoutineList.AddLast(routine); } }
/// <summary> /// 更新资源包请求 /// </summary> private void UpdateAssetBundleCreateRequest() { if (m_CurrAssetBundleCreateRequest != null) { if (m_CurrAssetBundleCreateRequest.isDone) { AssetBundle assetBundle = m_CurrAssetBundleCreateRequest.assetBundle; if (assetBundle != null) { GameEntry.Log(LogCategory.Resource, string.Format("资源包=>{0} 加载完毕", m_CurrAssetBundleInfo.AssetBundleName)); Reset(); if (OnLoadAssetBundleComplete != null) { OnLoadAssetBundleComplete(assetBundle); } } else { GameEntry.LogError("资源包=>{0} 加载失败", m_CurrAssetBundleInfo.AssetBundleName); Reset(); if (OnLoadAssetBundleComplete != null) { OnLoadAssetBundleComplete(null); } } } else { //加载进度 if (OnAssetBundleCreateUpdate != null) { OnAssetBundleCreateUpdate(m_CurrAssetBundleCreateRequest.progress); } } } }
/// <summary> /// 更新资源请求 /// </summary> private void UpdateAssetBundleRequest() { if (m_CurrAssetBundleRequest != null) { if (m_CurrAssetBundleRequest.isDone) { UnityEngine.Object obj = m_CurrAssetBundleRequest.asset; if (obj != null) { GameEntry.Log(LogCategory.Resource, string.Format("资源=>{0} 加载完毕", obj.name)); Reset(); if (OnLoadAssetComplete != null) { OnLoadAssetComplete(obj); } } else { GameEntry.LogError("资源包=>{0} 加载失败", "???"); Reset(); if (OnLoadAssetComplete != null) { OnLoadAssetComplete(null); } } } else { //加载进度 if (OnAssetUpdate != null) { OnAssetUpdate(m_CurrAssetBundleRequest.progress); } } } }
/// <summary> /// 下载文件 /// </summary> /// <param name="url"></param> /// <param name="onUpdate"></param> /// <param name="onComplete"></param> public void BeginDownloadSingle(string url, BaseAction <string, ulong, float> onUpdate = null, BaseAction <string> onComplete = null) { AssetBundleInfoEntity entity = GameEntry.Resource.ResourceManager.GetAssetBundleInfo(url); if (entity == null) { GameEntry.LogError("无效资源包=>" + url); return; } DownloadRoutine routine = GameEntry.Pool.DequeueClassObject <DownloadRoutine>(); routine.BeginDownload(url, entity, onUpdate, onComplete: (string fileUrl, DownloadRoutine rou) => { m_DownloadRoutineList.Remove(rou); GameEntry.Pool.EnqueueClassObject(routine); if (onComplete != null) { onComplete(fileUrl); } }); m_DownloadRoutineList.AddLast(routine); }