Exemple #1
0
        public override bool Equals(object obj)
        {
            AssetHashInfo other = obj as AssetHashInfo;

            if (other.Name.Equals(Name) && other.Hash.Equals(Hash))
            {
                return(true);
            }

            return(false);
        }
        //保存资源版本信息
        private static void SaveAssetVersion(string buildPath, BuildTarget target)
        {
            string targetBundlePath = Path.Combine(buildPath, target.ToString());

            if (!File.Exists(targetBundlePath))
            {
                return;
            }

            AssetBundleVersionInfo assetVersionInfo = new  AssetBundleVersionInfo();

            assetVersionInfo.Version             = _config.Version;
            assetVersionInfo.ManifestAssetBundle = target.ToString();
            assetVersionInfo.AssetHashInfos      = new List <AssetHashInfo>();

            AssetBundle         targetBundle = AssetBundle.LoadFromFile(targetBundlePath);
            AssetBundleManifest manifest     = targetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
            List <string>       assetNames   = new List <string>();

            assetNames.Add(target.ToString());
            assetNames.AddRange(manifest.GetAllAssetBundles());
            for (int i = 0; i < assetNames.Count; i++)
            {
                AssetHashInfo assetHashInfo = new AssetHashInfo();
                assetHashInfo.Name = assetNames[i];
                //AssetBundleManifest的hashcode 获取一直为00000000000000000000000000000000 于是用版本号代替
                assetHashInfo.Hash = i == 0?_config.Version.ToString():manifest.GetAssetBundleHash(assetNames[i]).ToString();
                assetVersionInfo.AssetHashInfos.Add(assetHashInfo);
                //删除manifest文件
                string manifestPath = Path.Combine(buildPath, assetNames[i] + ".manifeset");
                if (File.Exists(manifestPath))
                {
                    File.Delete(manifestPath);
                }
            }

            string json = JsonUtility.ToJson(assetVersionInfo);

            File.WriteAllText(Path.Combine(buildPath, _assetVersionTxt), json);
            targetBundle.Unload(true);
        }