Пример #1
0
        void updateAssets(AssetVersion newAsset, System.Action <bool> whenDownloadOver = null)
        {
            if (newAsset == null || curAssetVersion == null)
            {
                Debug.LogError("newAsset or localAsset null");
                if (whenDownloadOver != null)
                {
                    whenDownloadOver(false);
                }
                return;
            }
            Dictionary <string, Hash128> updateList = new Dictionary <string, Hash128>();

            Debug.Log("assetversion1:" + newAsset.ToStr() + "old kkkk:" + curAssetVersion.ToStr());
            AssetVersion.CompareAndGetUpdateList(curAssetVersion, newAsset, out updateList);
            //更新总的依赖文件
            loader.UpdateManifestFromServer(AssetBundleInfo.assetPath_server, (AssetBundleManifest am) =>
            {
                Debug.Log("服务器更新了manifest"); AssetBundleInfo.SetManifest(am);
                if (updateList != null)
                {
                    loader.UpdateFromServer(AssetBundleInfo.assetPath_server, updateList, whenDownloadOver);
                }
                else
                {
                    if (whenDownloadOver != null)
                    {
                        whenDownloadOver(true);
                    }
                }
            });

            //loader.UpdateFromServer()
        }
Пример #2
0
 public static bool CompareBundlesInfo(AssetVersion a, AssetVersion b)
 {
     if (a == null || b == null)
     {
         return(false);
     }
     if (a.bundlesInfo.Count != a.bundlesInfo.Count)
     {
         return(false);
     }
     foreach (var tem in a.bundlesInfo)
     {
         if (!b.bundlesInfo.ContainsKey(tem.Key))
         {
             return(false);
         }
         else
         {
             if (tem.Value != b.bundlesInfo[tem.Key])
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #3
0
 public static void CompareAndGetUpdateList(AssetVersion oldRes, AssetVersion newRes, out Dictionary <string, Hash128> updateList)
 {
     updateList = new Dictionary <string, Hash128>();
     if (oldRes == null || newRes == null)
     {
         Debug.LogError("oldRes or newRes is null");
         return;
     }
     Debug.Log("newRes.bundlesInfo:" + newRes.bundlesInfo.Count + "  oldRes.bundlesInfo:" + oldRes.bundlesInfo.Count);
     foreach (KeyValuePair <string, Hash128> tem in newRes.bundlesInfo)
     {
         if (oldRes.bundlesInfo == null)
         {
             updateList = newRes.bundlesInfo;
             return;
         }
         if (!oldRes.bundlesInfo.ContainsKey(tem.Key))
         {
             Debug.Log("新增了一个包:" + tem.Key);
             updateList.Add(tem.Key, tem.Value);
         }
         else
         {
             if (tem.Value != oldRes.bundlesInfo[tem.Key])
             {
                 Debug.Log("资源包有修改:" + tem.Key); updateList.Add(tem.Key, tem.Value);
             }
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 解析资源信息
        /// </summary>
        /// <returns></returns>
        static AssetVersion DecodeLocalResourcesinfo()
        {
            TextAsset ta = Resources.Load(getPlatformFolder() + "/assetVersionInfo") as TextAsset;

            if (ta == null)
            {
                Debug.LogError("DecodeLocalResourcesinfo ERROR,not found resourcesinfo.txt at Resources Directory:" + getPlatformFolder());
                return(null);
            }
            AssetVersion local = AssetVersion.FromString(ta.text);

            return(local);
        }
Пример #5
0
 public AssetBase()
 {
     gloabalSourceDic = new Dictionary <string, Object>();
     sceneSourceDic   = new Dictionary <string, Object>();
     curAssetVersion  = getAssetinfoFromLocal();
     abConfig         = loadABConfig();
     gameAssetConfig  = loadGameAssetConfig();
     if (curAssetVersion == null)
     {
         Debug.LogError("curAssetVersion null");
     }
     else
     {
         Debug.Log("本地资源版本号:" + curAssetVersion.assetVersion);
         //    AppFacade.Ins.Log(BugType.log, "本地资源版本号"+ curAssetVersion.assetVersion);
     }
     loader = new AssetBundleLoader();
 }
Пример #6
0
        public static AssetVersion FromString(string strInfo)
        {
            string[] tem = new string[3];
            tem = strInfo.Split('|');
            if (tem[0] == string.Empty)
            {
                Debug.Log("error ..0");
                return(null);
            }
            AssetVersion rinfo = new AssetVersion();

            if (!int.TryParse(tem[0], out rinfo.assetVersion))
            {
                Debug.Log("error ..1");
                return(null);
            }
            rinfo.manifestName = tem[1];
            string[] bds    = tem[2].Split(',');
            string[] vector = new string[2];
            Dictionary <string, Hash128> dic = new Dictionary <string, Hash128>();

            for (int i = 0; i < bds.Length; i++)
            {
                vector = bds[i].Split('&');
                if (i == bds.Length - 1)
                {
                    continue;
                }
                if (vector.Length != 2)
                {
                    Debug.Log("error .. 3:" + vector.Length);
                    return(null);
                }
                if (vector[0] == string.Empty && vector[1] == string.Empty)
                {
                    continue;
                }
                dic.Add(vector[0], Hash128.Parse(vector[1]));
            }
            rinfo.bundlesInfo = dic;
            return(rinfo);
        }
Пример #7
0
        /// <summary>
        /// 拉资源配置信息
        /// </summary>
        /// <param name="url"></param>
        /// <param name="back"></param>
        void pullAssetinfoFromSer(System.Action <AssetVersion> back)
        {
            string VersionPath         = AssetBundleInfo.assetPath_server + "/" + "assetVersionInfo.txt"; //资源版本信息
            string ConfigPath          = AssetBundleInfo.assetPath_server + "/" + "abConfig.txt";         //资源包配置信息
            string GameAssetConfigPath = AssetBundleInfo.assetPath_server + "/" + "gameAssetConfig.txt";  //游戏资源预加载信息

            loader.LoadFileFromServer(GameAssetConfigPath, (string str0) => {
                gameAssetConfig = GameAssetConfig.FromStr(str0);
                loader.LoadFileFromServer(ConfigPath, (string str) => {
                    Debug.Log("config file download"); abConfig = AssetbundleConfig.FromStr(str);
                    loader.LoadFileFromServer(VersionPath, (string str1) => {
                        AssetVersion av = AssetVersion.FromString(str1);
                        if (back != null)
                        {
                            back(av);
                        }
                    });
                });
            });
        }
Пример #8
0
        /// <summary>
        /// 生成资源配置信息: 资源包信息, 资源与包的关系信息
        /// </summary>
        static void CreatResourceinfo()
        {
            string outputPath = AssetBundlesOutputPath;
            //if (Directory.Exists(outputPath))
            //{
            //    Directory.Delete(outputPath, true);
            //}
            //Directory.CreateDirectory(outputPath);
            Dictionary <string, Hash128> abDic = new Dictionary <string, Hash128>();

            GetABInfo(outputPath, ref abDic);
            AssetVersion rinfo = new AssetVersion();

            rinfo.bundlesInfo = abDic;

            abConfig.resourceVersion = rinfo.assetVersion;
            Debug.Log(rinfo.assetVersion);
            rinfo.manifestName = outputPath.Substring(outputPath.LastIndexOf("\\") + 1);
            Debug.Log("manifestname = " + rinfo.manifestName);
            //File.Create(outputPath+"assetResources.txt",
            FileHelper.CreateFile(outputPath, "\\assetVersionInfo.txt", rinfo.ToStr(), false);
            FileHelper.CreateFile(outputPath, "\\abConfig.txt", abConfig.ToString(), false);

            //AssetVersion localRinfo = DecodeLocalResourcesinfo();
            //Debug.Log("old:" + rinfo.ToStr() + "   -new:" + localRinfo.ToStr());
            ////比较新的assetbundle与之前的是否一致
            //if (!AssetVersion.CompareBundlesInfo(rinfo, localRinfo))
            //{
            //    // rinfo.assetVersion = VRFramework.ResourceManager.AssetVersionNum + 1;
            //    abConfig.resourceVersion = rinfo.assetVersion;
            //    Debug.Log(rinfo.assetVersion);
            //    rinfo.manifestName = outputPath.Substring(outputPath.LastIndexOf("\\") + 1);
            //    //File.Create(outputPath+"assetResources.txt",
            //    FileHelper.CreateFile(outputPath, "\\assetVersionInfo.txt", rinfo.ToStr(), false);
            //    FileHelper.CreateFile(outputPath, "\\abConfig.txt", abConfig.ToString(), false);
            //    Debug.LogError("It's not an error!!!! -- 手动替换掉resources目录下的resourceinfo.txt文件");

            //    return;
            //}
            //Debug.Log("新的assetbundle包与原来的一致!");
        }
Пример #9
0
        AssetVersion getAssetinfoFromLocal()
        {
            string fullpath = AssetBundleInfo.assetPath_local + "/" + "assetVersionInfo.txt";

            if (File.Exists(fullpath))
            {
                StreamReader sr   = File.OpenText(fullpath);
                string       text = sr.ReadToEnd();
                sr.Close();
                return(AssetVersion.FromString(text));
            }
            else
            {
                fullpath = AssetBundleInfo.curPlatformFloder + "/assetVersionInfo";
                Debug.Log("fullpath:" + fullpath);
                TextAsset ta = Resources.Load <TextAsset>(fullpath);
                if (ta == null)
                {
                    Debug.LogError("not find AssetVersionInfo at resource dir");
                    return(null);
                }
                return(AssetVersion.FromString(ta.text));
            }
        }