Ejemplo n.º 1
0
        /// <summary>
        /// 服务器的AssetBundle 配置
        /// </summary>
        protected virtual IEnumerator GetServerAssetConfigureRecordText(System.Action callback)
        {
            Debug.LogInfor("GetServerABundleRecordText");
            WWW ww = new WWW(m_ServerAseetPath + m_AssetConfigurePath + ".txt");

            yield return(ww);

            if (string.IsNullOrEmpty(ww.error) == false)
            {
                Debug.LogError("GetServerABundleRecordText Fail  Error: " + ww.error);
                OnDownLoadServerConfigFail();
                yield break;
            }
            m_ServerConfigureStr = ww.text;  //保存配置文件
            m_ServerAssetRecord  = JsonMapper.ToObject <HotAssetRecordInfor>(ww.text);
            if (m_ServerAssetRecord == null)
            {
                Debug.LogError("Server ABInfor Can't Identify");
                OnDownLoadServerConfigFail();
                yield break;
            }
            if (callback != null)
            {
                callback();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 加载本地的AB资源配置文件
        /// </summary>
        protected void GetLocalAseetConfigureRecordText()
        {
            string assetText = "";
            string filePath  = m_AssetSaveTopPath + m_AssetConfigurePath + ".txt";

            //****首先读取外部的配置文件
            if (File.Exists(filePath))
            {
                Debug.LogInfor("GetLocalAseetConfigureRecordText  is OutStorage directory");
                assetText = File.ReadAllText(filePath);
            }
            else
            {
                Debug.LogInfor("GetLocalAseetConfigureRecordText  is Resources directory");
                TextAsset textAsset = Resources.Load <TextAsset>(m_AssetConfigurePath);
                if (textAsset == null)
                {
                    Debug.LogInfor("Resource Configure Not Exit");
                    m_LocalAssetRecord = null;
                    return;
                }
                assetText = textAsset.text;
            }//随包的  配置文件

            m_LocalAssetRecord = JsonMapper.ToObject <HotAssetRecordInfor>(assetText);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重置状态
        /// </summary>
        protected virtual void InitialState()
        {
            m_TotalDownLoadAssetCount   = 0;
            m_AllNeedDownLoadAssetCount = m_CurrentDownLoadCount = 0;

            m_AllDownLoadFailAssetRecord.Clear();
            m_AllNeedUpdateAssetPath.Clear();
            m_AllCompleteDownLoadAssetDic.Clear();

            m_LocalAssetRecord = m_ServerAssetRecord = null;

            m_IsCompleteMD5    = m_IsDownLoadServerConfigure = false;
            m_IsCompleteUpdate = false;
            m_IsUpdateRecorded = false;

            if (Directory.Exists(m_AssetSaveTopPath) == false)
            {
                Directory.CreateDirectory(m_AssetSaveTopPath);  //ABundle 资源目录初始化
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新本地的配置文件  防止由于意外下载完成一半而导致部分 Asset 已经更新但是配置文件没有更新的问题
        /// </summary>
        /// <param name="forceRecord">是否忽略下载的文件个数限制</param>
        protected virtual void UpdateLocalRecordConfigureText(bool forceRecord)
        {
            if (m_IsCompleteUpdate || m_AllCompleteDownLoadAssetDic.Count == 0)
            {
                //Debug.LogInfor("UpdateLocalRecordConfigureText   No Need");
                return;
            }//已经完成正常的更新流程

            if (m_ServerAssetRecord == null)
            {
                Debug.LogError("UpdateLocalRecordConfigureText Fail ,Server Configure is Null");
                return;
            }//服务器的配置文件不存在

            if (forceRecord == false && m_TotalDownLoadAssetCount % S_DownLoadCoutToRecord != 0)
            {
                return;   //避免频繁写入文件
            }
            m_IsUpdateRecorded = true;

            if (m_LocalAssetRecord == null)
            {
                m_LocalAssetRecord = new HotAssetRecordInfor();
            }

            #region  对比更新本地配置文件数据
            HotAssetInfor bundleInfor      = null;
            List <string> allNewRecordKeys = new List <string>();
            foreach (var abundleRecord in m_AllCompleteDownLoadAssetDic)
            {
                if (abundleRecord.Value)
                {
                    continue;  //已经被记录到本地了
                }
                if (m_LocalAssetRecord.m_AllAssetRecordsDic.TryGetValue(abundleRecord.Key, out bundleInfor))
                {
                    if (bundleInfor.m_MD5Code != m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key].m_MD5Code)
                    {
                        //   Debug.LogInfor("Need Update AssetBundle :" + abundleRecord.Key);
                        m_LocalAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key] = m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key];
                        allNewRecordKeys.Add(abundleRecord.Key);
                        continue;
                    }
                }
                else
                {
                    //Debug.LogInfor("New Add AssetBundle  :: " + abundleRecord.Key);
                    if (m_ServerAssetRecord.m_AllAssetRecordsDic.ContainsKey(abundleRecord.Key))
                    {
                        m_LocalAssetRecord.m_AllAssetRecordsDic.Add(abundleRecord.Key, m_ServerAssetRecord.m_AllAssetRecordsDic[abundleRecord.Key]);
                        allNewRecordKeys.Add(abundleRecord.Key);
                    }
                    continue;
                }
            }

            for (int dex = 0; dex < allNewRecordKeys.Count; ++dex)
            {
                m_AllCompleteDownLoadAssetDic[allNewRecordKeys[dex]] = true;
            }
            allNewRecordKeys.Clear();

            #endregion

            //***********更新本地配置文件
            if (File.Exists(m_AssetSaveTopPath + m_AssetConfigurePath))
            {
                File.Delete(m_AssetSaveTopPath + m_AssetConfigurePath);
            }
            File.WriteAllText(m_AssetSaveTopPath + m_AssetConfigurePath + ".txt", JsonMapper.ToJson(m_LocalAssetRecord));  //更新配置文件
        }