diff --git a/Assets/CatAsset/Editor/BuildPipeline/Task/FillBuildInfoParam.cs b/Assets/CatAsset/Editor/BuildPipeline/Task/FillBuildInfoParam.cs index bd002d32..476aba8c 100644 --- a/Assets/CatAsset/Editor/BuildPipeline/Task/FillBuildInfoParam.cs +++ b/Assets/CatAsset/Editor/BuildPipeline/Task/FillBuildInfoParam.cs @@ -93,15 +93,15 @@ public ReturnCode Run() } //计算补丁包 - //读取上次完整构建时的资源文件MD5信息 + //读取上次完整构建时的资源文件AssetCache信息 folder = EditorUtil.GetAssetCacheManifestFolder(config.OutputRootDirectory); path = RuntimeUtil.GetRegularPath(Path.Combine(folder, AssetCacheManifest.ManifestJsonFileName)); string json = File.ReadAllText(path); AssetCacheManifest assetCacheManifest = JsonUtility.FromJson(json); - Dictionary cacheMD5Dict = assetCacheManifest.GetCacheDict(); + Dictionary assetCacheDict = assetCacheManifest.GetCacheDict(); - //当前资源文件的md5字典 - Dictionary curMD5Dict = new Dictionary(); + //当前资源文件的AssetCache字典 + Dictionary curAssetCacheDict = new Dictionary(); //资源名 -> 是否已变化 Dictionary assetChangeStateDict = new Dictionary(); @@ -118,7 +118,7 @@ public ReturnCode Run() var asset = bundle.Assets[j]; //1.自身是否变化 - bool isChanged = IsChangedAsset(asset.Name, assetChangeStateDict, cacheMD5Dict, curMD5Dict, + bool isChanged = IsChangedAsset(asset.Name, assetChangeStateDict, assetCacheDict, curAssetCacheDict, assetToBundle, cacheAssetToBundle); if (!isChanged) @@ -128,7 +128,7 @@ public ReturnCode Run() { foreach (string upStream in upStreamList) { - isChanged = IsChangedAsset(upStream, assetChangeStateDict, cacheMD5Dict, curMD5Dict, + isChanged = IsChangedAsset(upStream, assetChangeStateDict, assetCacheDict, curAssetCacheDict, assetToBundle, cacheAssetToBundle); if (isChanged) { @@ -145,7 +145,7 @@ public ReturnCode Run() { foreach (string downStream in downStreamList) { - isChanged = IsChangedAsset(downStream, assetChangeStateDict, cacheMD5Dict, curMD5Dict, + isChanged = IsChangedAsset(downStream, assetChangeStateDict, assetCacheDict, curAssetCacheDict, assetToBundle, cacheAssetToBundle); if (isChanged) { @@ -196,7 +196,7 @@ public ReturnCode Run() /// 是否为已变化的资源 /// private bool IsChangedAsset(string assetName, Dictionary assetChangeStateDict, - Dictionary cacheMD5Dict, Dictionary curMD5Dict, + Dictionary assetCacheDict, Dictionary curAssetCacheDict, Dictionary assetToBundle, Dictionary cacheAssetToBundle) { @@ -207,19 +207,19 @@ private bool IsChangedAsset(string assetName, Dictionary assetChan } //1.新资源 - if (!cacheMD5Dict.TryGetValue(assetName, out string cachedMD5)) + if (!assetCacheDict.TryGetValue(assetName, out var assetCache)) { assetChangeStateDict.Add(assetName, true); return true; } //2.变化的旧资源 - if (!curMD5Dict.TryGetValue(assetName, out string curMD5)) + if (!curAssetCacheDict.TryGetValue(assetName, out var curAssetCache)) { - curMD5 = RuntimeUtil.GetFileMD5(assetName); - curMD5Dict.Add(assetName, curMD5); + curAssetCache = AssetCacheManifest.AssetCacheInfo.Create(assetName); + curAssetCacheDict.Add(assetName, curAssetCache); } - if (curMD5 != cachedMD5) + if (curAssetCache != assetCache) { assetChangeStateDict.Add(assetName, true); return true; @@ -231,8 +231,6 @@ private bool IsChangedAsset(string assetName, Dictionary assetChan assetChangeStateDict.Add(assetName, true); return true; } - - //未变化 assetChangeStateDict.Add(assetName, false); diff --git a/Assets/CatAsset/Editor/BuildPipeline/Task/WriteCacheFile.cs b/Assets/CatAsset/Editor/BuildPipeline/Task/WriteCacheFile.cs index 40fb7ad3..321f10bb 100644 --- a/Assets/CatAsset/Editor/BuildPipeline/Task/WriteCacheFile.cs +++ b/Assets/CatAsset/Editor/BuildPipeline/Task/WriteCacheFile.cs @@ -40,12 +40,8 @@ public ReturnCode Run() { foreach (AssetManifestInfo assetManifestInfo in bundleManifestInfo.Assets) { - string md5 = RuntimeUtil.GetFileMD5(assetManifestInfo.Name); - assetCacheManifest.Caches.Add(new AssetCacheManifest.AssetCache() - { - Name = assetManifestInfo.Name, - MD5 = md5, - }); + AssetCacheManifest.AssetCacheInfo cacheInfo = AssetCacheManifest.AssetCacheInfo.Create(assetManifestInfo.Name); + assetCacheManifest.Caches.Add(cacheInfo); } } string json = EditorJsonUtility.ToJson(assetCacheManifest,true); diff --git a/Assets/CatAsset/Editor/Misc/AssetCacheManifest.cs b/Assets/CatAsset/Editor/Misc/AssetCacheManifest.cs index 3655e342..1d560431 100644 --- a/Assets/CatAsset/Editor/Misc/AssetCacheManifest.cs +++ b/Assets/CatAsset/Editor/Misc/AssetCacheManifest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using CatAsset.Runtime; namespace CatAsset.Editor { @@ -9,11 +10,52 @@ namespace CatAsset.Editor [Serializable] public class AssetCacheManifest { + /// + /// 资源缓存信息 + /// [Serializable] - public class AssetCache + public struct AssetCacheInfo : IEquatable { public string Name; public string MD5; + public string MetaMD5; + + public bool Equals(AssetCacheInfo other) + { + return Name == other.Name && MD5 == other.MD5 && MetaMD5 == other.MetaMD5; + } + + public override bool Equals(object obj) + { + return obj is AssetCacheInfo other && Equals(other); + } + + public override int GetHashCode() + { + return HashCode.Combine(Name, MD5, MetaMD5); + } + + public static bool operator ==(AssetCacheInfo a,AssetCacheInfo b) + { + return Equals(a, b); + } + + public static bool operator !=(AssetCacheInfo a,AssetCacheInfo b) + { + return !(a == b); + } + + public static AssetCacheInfo Create(string assetName) + { + AssetCacheInfo assetCacheInfo = new AssetCacheInfo + { + Name = assetName, + MD5 = RuntimeUtil.GetFileMD5(assetName), + MetaMD5 = RuntimeUtil.GetFileMD5($"{assetName}.meta") + }; + return assetCacheInfo; + } + } /// @@ -22,17 +64,19 @@ public class AssetCache public const string ManifestJsonFileName = "AssetCacheManifest.json"; - public List Caches = new List(); + public List Caches = new List(); - public Dictionary GetCacheDict() + public Dictionary GetCacheDict() { - Dictionary result = new Dictionary(); - foreach (AssetCache assetCache in Caches) + Dictionary result = new Dictionary(); + foreach (AssetCacheInfo assetCache in Caches) { - result.Add(assetCache.Name,assetCache.MD5); + result.Add(assetCache.Name,assetCache); } return result; } + + } } \ No newline at end of file