/// <summary> /// 更新 /// </summary> public void OnUpdate() { if (m_CurrSceneIsLoading) { var curr = m_SceneLoaderList.First; while (curr != null) { curr.Value.OnUpdate(); curr = curr.Next; } float currTarget = GetCurrTotalProgress(); float finalTarget = 0.9f * m_NeedLoadOrUnloadSceneDetailCount; if (currTarget >= finalTarget) { currTarget = m_NeedLoadOrUnloadSceneDetailCount; } if (m_CurrProgress < m_NeedLoadOrUnloadSceneDetailCount && m_CurrProgress <= currTarget) { m_CurrProgress = m_CurrProgress + Time.deltaTime * m_NeedLoadOrUnloadSceneDetailCount * 1; m_CurrLoadingParam.IntParam1 = (int)LoadingType.ChangeScene; m_CurrLoadingParam.FloatParam1 = (m_CurrProgress / m_NeedLoadOrUnloadSceneDetailCount); GameEntry.Event.CommonEvent.Dispatch(SysEventId.LoadingProgressChange, m_CurrLoadingParam); } else if (m_CurrProgress >= m_NeedLoadOrUnloadSceneDetailCount) { GameEntry.Log(LogCategory.Normal, "场景加载完毕"); m_NeedLoadOrUnloadSceneDetailCount = 0; m_CurrLoadOrUnloadSceneDetailCount = 0; m_CurrSceneIsLoading = false; GameEntry.UI.CloseUIForm(UIFormId.Loading); m_CurrLoadingParam.Reset(); GameEntry.Pool.EnqueueClassObject(m_CurrLoadingParam); if (m_OnComplete != null) { m_OnComplete(); } } } }
public override void OnEnter() { base.OnEnter(); GameEntry.Log(LogCategory.Procedure, "OnEnter ProcedurePreload"); GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadOneDataTableComplete, OnLoadOneDataTableComplete); GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadDataTableComplete, OnLoadDataTableComplete); GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadLuaDataTableComplete, OnLoadLuaDataTableComplete); GameEntry.Log(LogCategory.Normal, "预加载开始"); m_PreloadParams = GameEntry.Pool.DequeueClassObject <BaseParams>(); m_PreloadParams.Reset(); GameEntry.Event.CommonEvent.Dispatch(SysEventId.PreloadBegin); m_TargetProgress = 99; #if !DISABLE_ASSETBUNDLE GameEntry.Resource.InitAssetInfo(); #endif GameEntry.DataTable.LoadDataTableAsync(); }
/// <summary> /// 下载初始资源 /// </summary> private void DownloadInitResources() { GameEntry.Event.CommonEvent.Dispatch(SysEventId.CheckVersionBeginDownload); m_DownloadingParams = GameEntry.Pool.DequeueClassObject <BaseParams>(); m_DownloadingParams.Reset(); m_NeedDownloadList.Clear(); var enumerator = m_CNDVersionDic.GetEnumerator(); while (enumerator.MoveNext()) { AssetBundleInfoEntity entity = enumerator.Current.Value; if (entity.IsFirstData) { m_NeedDownloadList.AddLast(entity.AssetBundleName); } } GameEntry.Download.BeginDownloadMulit(m_NeedDownloadList, OnDownloadMulitUpdate, OnDownloadMulitComplete); }
/// <summary> /// 开始检查更新 /// </summary> private void BeginCheckVersionChange() { m_DownloadingParams = GameEntry.Pool.DequeueClassObject <BaseParams>(); m_DownloadingParams.Reset(); //需要删除的文件 LinkedList <string> delList = new LinkedList <string>(); //可写区资源MD5和CDN资源MD5不一致的文件 LinkedList <string> inconformityList = new LinkedList <string>(); LinkedList <string> needDownloadList = new LinkedList <string>(); #region 找出需要删除的文件进行删除 var enumerator = m_LocalAssetsVersionDic.GetEnumerator(); while (enumerator.MoveNext()) { string assetBundleName = enumerator.Current.Key; //去CDN对比 AssetBundleInfoEntity cdnAssetBundleInfo = null; if (m_CNDVersionDic.TryGetValue(assetBundleName, out cdnAssetBundleInfo)) { //可写区有 CDN也有 if (!cdnAssetBundleInfo.MD5.Equals(enumerator.Current.Value.MD5, StringComparison.CurrentCultureIgnoreCase)) { //如果MD5不一致 加入不一致链表 inconformityList.AddLast(assetBundleName); } } else { //可写区有 CDN上没有 加入删除列表 delList.AddLast(assetBundleName); } } //循环判断这个文件在只读区的MD5和CDN是否一致 一致的进行删除 不一致的进行重新下载 LinkedListNode <string> currInconformity = inconformityList.First; while (currInconformity != null) { AssetBundleInfoEntity cdnAssetBundleInfo = null; m_CNDVersionDic.TryGetValue(currInconformity.Value, out cdnAssetBundleInfo); AssetBundleInfoEntity streamingAssetsAssetBundleInfo = null; if (m_StreamingAssetsVersionDic != null) { m_StreamingAssetsVersionDic.TryGetValue(currInconformity.Value, out streamingAssetsAssetBundleInfo); } if (streamingAssetsAssetBundleInfo == null) { //如果只读区 没有 needDownloadList.AddLast(currInconformity.Value); } else { //判断 是否一致 if (cdnAssetBundleInfo.MD5.Equals(streamingAssetsAssetBundleInfo.MD5, StringComparison.CurrentCultureIgnoreCase)) { //一致 delList.AddLast(currInconformity.Value); } else { //不一致 needDownloadList.AddLast(currInconformity.Value); } } currInconformity = currInconformity.Next; } #endregion #region 除需要删除的 LinkedListNode <string> currDel = delList.First; while (currDel != null) { string filePath = string.Format("{0}/{1}", GameEntry.Resource.LocalFilePath, currDel.Value); if (File.Exists(filePath)) { File.Delete(filePath); } LinkedListNode <string> next = currDel.Next; delList.Remove(currDel); currDel = next; } #endregion #region 检查需要下载的 enumerator = m_CNDVersionDic.GetEnumerator(); while (enumerator.MoveNext()) { AssetBundleInfoEntity cdnAssetBundleInfo = enumerator.Current.Value; if (cdnAssetBundleInfo.IsFirstData) { //检查初始资源 if (!m_LocalAssetsVersionDic.ContainsKey(cdnAssetBundleInfo.AssetBundleName)) { //如果可写区没有 则去只读区判断一次 AssetBundleInfoEntity streamingAssetsAssetBundleInfo = null; if (m_StreamingAssetsVersionDic != null) { m_StreamingAssetsVersionDic.TryGetValue(cdnAssetBundleInfo.AssetBundleName, out streamingAssetsAssetBundleInfo); } if (streamingAssetsAssetBundleInfo == null) { //只读区不存在 needDownloadList.AddLast(cdnAssetBundleInfo.AssetBundleName); } else { //只读区存在 验证MD5 if (!cdnAssetBundleInfo.MD5.Equals(streamingAssetsAssetBundleInfo.MD5, StringComparison.CurrentCultureIgnoreCase)) { //MD5不一致 needDownloadList.AddLast(cdnAssetBundleInfo.AssetBundleName); } } } } } #endregion GameEntry.Event.CommonEvent.Dispatch(SysEventId.CheckVersionBeginDownload); //进行下载 GameEntry.Download.BeginDownloadMulit(needDownloadList, OnDownloadMulitUpdate, OnDownloadMulitComplete); }