/// <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) { Debug.Log("场景加载完毕"); 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.LoadDataTableComplete, OnLoadDataTableComplete); GameEntry.Event.CommonEvent.AddEventListener(SysEventId.LoadOneDataTableComplete, OnLoadOneDataTableComplete); 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_TargerProgress = 98; #if !DISABLE_ASSETBUNDLE GameEntry.Resource.InitAssetInfo(); #endif GameEntry.DataTable.LoadDataTableAsync(); }
/// <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> inconformtyList = 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_CDNVersionDic.TryGetValue(assetBundleName, out cdnAssetBundleInfo)) { //可写区有 cdn也有 if (!cdnAssetBundleInfo.MD5.Equals(enumerator.Current.Value.MD5, StringComparison.CurrentCultureIgnoreCase)) { //如果md5不一致 加入不一致列表 inconformtyList.AddLast(assetBundleName); } } else { //可写区有 cdn上没有 加入删除列表 delList.AddLast(assetBundleName); } } //循环判断这个文件在只读区的md5和cdn是否一致 一致的进行删除 不一致的进行重新下载 LinkedListNode <string> currInconformity = inconformtyList.First; while (currInconformity != null) { AssetBundleInfoEntity cdnAssetBundleInfo = null; m_CDNVersionDic.TryGetValue(currInconformity.Value, out cdnAssetBundleInfo); AssetBundleInfoEntity streamingAssetAssetBundleInfo = null; if (m_StreamingAssetsVersionDic != null) { m_StreamingAssetsVersionDic.TryGetValue(currInconformity.Value, out streamingAssetAssetBundleInfo); } if (streamingAssetAssetBundleInfo == null) { //如果只读区 没有 needDownloadList.AddLast(currInconformity.Value); } else { //判断 是否一致 if (cdnAssetBundleInfo.MD5.Equals(streamingAssetAssetBundleInfo.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_CDNVersionDic.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); }