From b7c90096f6685761faceda0d2e29c3cbcc0477e4 Mon Sep 17 00:00:00 2001 From: Alienjack Date: Wed, 3 Sep 2025 17:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=AE=BE=E7=BD=AE=E5=88=86?= =?UTF-8?q?=E9=A1=B5=EF=BC=8C=E9=9A=90=E8=97=8F=E4=B8=8D=E5=BF=85=E8=A6=81?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E7=9A=84=E9=A1=B9=E7=9B=AE=EF=BC=8C=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E7=A7=BB=E5=85=A5=E6=89=93=E5=8C=85=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=88=86=E9=A1=B5=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/VersionFlow/Builder/Builder.asset | 2 +- .../VersionFlow/Editor/BuilderConfigEditor.cs | 2 - .../Editor/VersionFlowSettingWnd.cs | 1 + Assets/VersionFlow/Runtime/BuilderConfig.cs | 620 +++++++++--------- 4 files changed, 314 insertions(+), 311 deletions(-) diff --git a/Assets/VersionFlow/Builder/Builder.asset b/Assets/VersionFlow/Builder/Builder.asset index 7695a84..2625000 100644 --- a/Assets/VersionFlow/Builder/Builder.asset +++ b/Assets/VersionFlow/Builder/Builder.asset @@ -21,7 +21,7 @@ MonoBehaviour: - VersionFlow.Editors.PatchUpLoader_AliOSS m_values: - '{"UploadRoot":"./LocalPatch"}' - - '{"BucketName":"asdad","UploadPath":"asdasd","accessKeyId":"asdasd","accessKeySecret":"dasdad","endPoint":"asdasd"}' + - '{"BucketName":"BUCKET","UploadPath":"Project_DEMO","accessKeyId":"00000000","accessKeySecret":"asdasdasd","endPoint":"oss.endpoint.com"}' Options: 288 Groups: - GroupName: Backpack diff --git a/Assets/VersionFlow/Editor/BuilderConfigEditor.cs b/Assets/VersionFlow/Editor/BuilderConfigEditor.cs index a2f93db..4e1df7a 100644 --- a/Assets/VersionFlow/Editor/BuilderConfigEditor.cs +++ b/Assets/VersionFlow/Editor/BuilderConfigEditor.cs @@ -36,8 +36,6 @@ namespace VersionFlow.Editors public override void OnInspectorGUI() { - base.OnInspectorGUI(); - DrawUploader(); var builder = target as BuilderConfig; diff --git a/Assets/VersionFlow/Editor/VersionFlowSettingWnd.cs b/Assets/VersionFlow/Editor/VersionFlowSettingWnd.cs index cfda22c..7d8bbde 100644 --- a/Assets/VersionFlow/Editor/VersionFlowSettingWnd.cs +++ b/Assets/VersionFlow/Editor/VersionFlowSettingWnd.cs @@ -21,6 +21,7 @@ namespace VersionFlow.Editors private void OnEnable() { + titleContent = new GUIContent("VersionFlow"); m_builder = PatchUploaderUtility.FindBuilderInProject(); m_builderEditor = Editor.CreateEditor(m_builder); diff --git a/Assets/VersionFlow/Runtime/BuilderConfig.cs b/Assets/VersionFlow/Runtime/BuilderConfig.cs index 403adda..306270d 100644 --- a/Assets/VersionFlow/Runtime/BuilderConfig.cs +++ b/Assets/VersionFlow/Runtime/BuilderConfig.cs @@ -1,234 +1,238 @@ -#if UNITY_EDITOR -using System; -using System.Collections.Generic; -using System.IO; -using UnityEditor; -using UnityEngine; -using UnityEngine.UIElements; -using VersionFlow.Runtime.Builder; - -namespace VersionFlow.Runtime -{ - [CreateAssetMenu(fileName = "Builder", menuName = "CreateBuilder")] - public class BuilderConfig : ScriptableObject - { - public static bool ShowBuilderMarker - { - get => EditorPrefs.GetBool("ShowBuilderMarker", true); - set => EditorPrefs.SetBool("ShowBuilderMarker", value); - } - - [SerializeField] - internal VersionFlowSetting vfSetting; - [SerializeField] - internal StyleSheet debugGraphBackgroundStyle; - +#if UNITY_EDITOR +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; +using VersionFlow.Runtime.Builder; + +namespace VersionFlow.Runtime +{ + [CreateAssetMenu(fileName = "Builder", menuName = "CreateBuilder")] + public class BuilderConfig : ScriptableObject + { + public static bool ShowBuilderMarker + { + get => EditorPrefs.GetBool("ShowBuilderMarker", true); + set => EditorPrefs.SetBool("ShowBuilderMarker", value); + } + [SerializeField] - [HideInInspector] - internal string uploaderClassName; + [HideInInspector] + internal VersionFlowSetting vfSetting; [SerializeField] - [HideInInspector] - internal UploaderCfgDict UploaderCfgDict; - - public BuildAssetBundleOptions Options; - [HideInInspector] - public List Groups; - public ShaderVariantCollection SVC; - - [HideInInspector] - public bool DuplicateBundleBeInstallBundle; - [HideInInspector] - public bool ShaderBundleBeInstallBundle; - - public delegate void OnCalcBundleHashHandle(string bundleOutputPath, List buildInfoList, Dictionary bundleExtraInfo, AssetBundleManifest report); - public OnCalcBundleHashHandle OnCalcBundleHash; - - public BundleManifest Build(string version, out string outputPath, out Dictionary bundleExtraInfo) - { - Dictionary assetsToBuild = CollectAssetsToBuild(out var shaderGroup); - bundleExtraInfo = new Dictionary(); - var duplicateBuilds = CalcDuplicateBuild(assetsToBuild, shaderGroup, ref bundleExtraInfo, DuplicateBundleBeInstallBundle); - List buildInfoList = CalcNormalBuild(assetsToBuild, ref bundleExtraInfo); - - buildInfoList.AddRange(duplicateBuilds); - - - outputPath = $"./Output/Bundles/{VersionFlowX.PlatformFoldName}"; + [HideInInspector] + internal StyleSheet debugGraphBackgroundStyle; + + [SerializeField] + [HideInInspector] + internal string uploaderClassName; + [SerializeField] + [HideInInspector] + internal UploaderCfgDict UploaderCfgDict; + + [HideInInspector] + public BuildAssetBundleOptions Options; + [HideInInspector] + public List Groups; + [HideInInspector] + public ShaderVariantCollection SVC; + + [HideInInspector] + public bool DuplicateBundleBeInstallBundle; + [HideInInspector] + public bool ShaderBundleBeInstallBundle; + + public delegate void OnCalcBundleHashHandle(string bundleOutputPath, List buildInfoList, Dictionary bundleExtraInfo, AssetBundleManifest report); + public OnCalcBundleHashHandle OnCalcBundleHash; + + public BundleManifest Build(string version, out string outputPath, out Dictionary bundleExtraInfo) + { + Dictionary assetsToBuild = CollectAssetsToBuild(out var shaderGroup); + bundleExtraInfo = new Dictionary(); + var duplicateBuilds = CalcDuplicateBuild(assetsToBuild, shaderGroup, ref bundleExtraInfo, DuplicateBundleBeInstallBundle); + List buildInfoList = CalcNormalBuild(assetsToBuild, ref bundleExtraInfo); + + buildInfoList.AddRange(duplicateBuilds); + + + outputPath = $"./Output/Bundles/{VersionFlowX.PlatformFoldName}"; Directory.CreateDirectory(outputPath); - var report = BuildPipeline.BuildAssetBundles(outputPath, buildInfoList.ToArray(), Options, EditorUserBuildSettings.activeBuildTarget); + var report = BuildPipeline.BuildAssetBundles(outputPath, buildInfoList.ToArray(), Options, EditorUserBuildSettings.activeBuildTarget); if (report != null) - OnCalcBundleHash.Invoke(outputPath, buildInfoList, bundleExtraInfo, report); - - var manifest = BundleManifest.Create(version, bundleExtraInfo, report, outputPath); - - return manifest; - } - - public List CompareBundleManifest(BundleManifest @new, BundleManifest old) - { - List result = new List(); - foreach (var bundle in @new.Bundles) - { - var oldBundle = old?.GetBundleByName(bundle.BundleName); - result.Add(new BundleCompare(bundle, oldBundle)); - } - //收集被移除的bundle - if (old != null && old.Bundles != null) - { - foreach (var oldBundle in old.Bundles) - { - var newBundle = @new.GetBundleByName(oldBundle.BundleName); - if (newBundle == null) - result.Add(new BundleCompare(null, oldBundle)); - } - } - return result; - } - - private static List CalcNormalBuild(Dictionary assetsToBuild, ref Dictionary bundleExtraInfo) - { - Dictionary> willBuilds = new Dictionary>(); - foreach (var item in assetsToBuild) - { - var assetInfo = item.Value; - if (!willBuilds.ContainsKey(assetInfo.BundleName)) - { - willBuilds[assetInfo.BundleName] = new HashSet(); - } - - BundleExtraInfo info = new BundleExtraInfo(); - if (!bundleExtraInfo.TryGetValue(assetInfo.BundleName, out info)) - { - info = new BundleExtraInfo(); - bundleExtraInfo[assetInfo.BundleName] = info; - //记录Bundle所属Group - info.GroupName = assetInfo.Group.GroupName; - //如果资源所属Group设置了可选Bundle,则标记Asset所在Bundle为可选下载Bundle - info.IsOptionBundle = assetInfo.Group.OptionBundle; - //如果资源所属Group设置了ShaderOnly,则标记Asset所在Bundle为ShaderBundle - info.ShaderBundle = assetInfo.Group.ShaderBundle; - //如果资源所属Group设置了随包资源标记,则标记Asset所在Bundle为随包资源 - info.IsInstallBundle = assetInfo.Group.InstallReady; - } - - willBuilds[assetInfo.BundleName].Add(assetInfo.FullName); - } - - List buildInfoList = new List(); - foreach (var item in willBuilds) - { - var buildInfo = new AssetBundleBuild { assetBundleName = item.Key }; - List assetPaths = new List(); - foreach (var assetPath in item.Value) - { - assetPaths.Add(assetPath); - } - buildInfo.assetNames = assetPaths.ToArray(); - buildInfoList.Add(buildInfo); - } - - return buildInfoList; - } - - private static List CalcDuplicateBuild(Dictionary assetsToBuild, BuildEntity shaderGroup, ref Dictionary bundleExtraInfo, bool DuplicateBundleBeInstallBundle) - { - Dictionary dependencyAssetsNotBuild = new Dictionary(); - foreach (var asset in assetsToBuild.Values) - { - foreach (var depAsset in asset.dependencyAssets) - { - if (assetsToBuild.ContainsKey(depAsset)) continue;//跳过原本就会打包的Asset - - if (dependencyAssetsNotBuild.ContainsKey(depAsset)) - dependencyAssetsNotBuild[depAsset]++; - else - dependencyAssetsNotBuild[depAsset] = 1; - } - } - - AssetBundleBuild duplicateBuild = new AssetBundleBuild { assetBundleName = "duplicate.bundle" }; - - bundleExtraInfo[duplicateBuild.assetBundleName] = new BundleExtraInfo - { - BundleName = duplicateBuild.assetBundleName.ToLower(), - GroupName = null, - IsOptionBundle = false, - ShaderBundle = false, - IsInstallBundle = DuplicateBundleBeInstallBundle, - }; - - List duplicateAssets = new List(); - - //重复依赖资源生成打包配置 - foreach (var item in dependencyAssetsNotBuild) - { - var assetPath = item.Key; - var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - - //shader类型资源进shaderbundle,而不进duplicate.bundle - if (assetType == typeof(Shader) || assetType == typeof(ShaderVariantCollection)) - { - var shaderAsset = new Asset(assetPath); - shaderAsset.Group = shaderGroup; - shaderAsset.BundleName = "ShaderFromSVC_Together.bundle".ToLower(); - assetsToBuild[assetPath] = shaderAsset; - continue; - } - - if (item.Value == 1) continue; //只有一次依赖的跳过 - duplicateAssets.Add(assetPath); - } - duplicateBuild.assetNames = duplicateAssets.ToArray(); - return new List { duplicateBuild }; - } - - private Dictionary CollectAssetsToBuild(out BuildEntity shaderGroup) - { - Dictionary assetsToBuild = new Dictionary(); - int totalCount = Groups.Count; - int step = 0; - foreach (var group in Groups) + OnCalcBundleHash.Invoke(outputPath, buildInfoList, bundleExtraInfo, report); + + var manifest = BundleManifest.Create(version, bundleExtraInfo, report, outputPath); + + return manifest; + } + + public List CompareBundleManifest(BundleManifest @new, BundleManifest old) + { + List result = new List(); + foreach (var bundle in @new.Bundles) { - EditorUtility.DisplayProgressBar($"收集打包资源{step}/{totalCount}", $"{group.GroupName}", step * 1f / totalCount); + var oldBundle = old?.GetBundleByName(bundle.BundleName); + result.Add(new BundleCompare(bundle, oldBundle)); + } + //收集被移除的bundle + if (old != null && old.Bundles != null) + { + foreach (var oldBundle in old.Bundles) + { + var newBundle = @new.GetBundleByName(oldBundle.BundleName); + if (newBundle == null) + result.Add(new BundleCompare(null, oldBundle)); + } + } + return result; + } + + private static List CalcNormalBuild(Dictionary assetsToBuild, ref Dictionary bundleExtraInfo) + { + Dictionary> willBuilds = new Dictionary>(); + foreach (var item in assetsToBuild) + { + var assetInfo = item.Value; + if (!willBuilds.ContainsKey(assetInfo.BundleName)) + { + willBuilds[assetInfo.BundleName] = new HashSet(); + } + + BundleExtraInfo info = new BundleExtraInfo(); + if (!bundleExtraInfo.TryGetValue(assetInfo.BundleName, out info)) + { + info = new BundleExtraInfo(); + bundleExtraInfo[assetInfo.BundleName] = info; + //记录Bundle所属Group + info.GroupName = assetInfo.Group.GroupName; + //如果资源所属Group设置了可选Bundle,则标记Asset所在Bundle为可选下载Bundle + info.IsOptionBundle = assetInfo.Group.OptionBundle; + //如果资源所属Group设置了ShaderOnly,则标记Asset所在Bundle为ShaderBundle + info.ShaderBundle = assetInfo.Group.ShaderBundle; + //如果资源所属Group设置了随包资源标记,则标记Asset所在Bundle为随包资源 + info.IsInstallBundle = assetInfo.Group.InstallReady; + } + + willBuilds[assetInfo.BundleName].Add(assetInfo.FullName); + } + + List buildInfoList = new List(); + foreach (var item in willBuilds) + { + var buildInfo = new AssetBundleBuild { assetBundleName = item.Key }; + List assetPaths = new List(); + foreach (var assetPath in item.Value) + { + assetPaths.Add(assetPath); + } + buildInfo.assetNames = assetPaths.ToArray(); + buildInfoList.Add(buildInfo); + } + + return buildInfoList; + } + + private static List CalcDuplicateBuild(Dictionary assetsToBuild, BuildEntity shaderGroup, ref Dictionary bundleExtraInfo, bool DuplicateBundleBeInstallBundle) + { + Dictionary dependencyAssetsNotBuild = new Dictionary(); + foreach (var asset in assetsToBuild.Values) + { + foreach (var depAsset in asset.dependencyAssets) + { + if (assetsToBuild.ContainsKey(depAsset)) continue;//跳过原本就会打包的Asset + + if (dependencyAssetsNotBuild.ContainsKey(depAsset)) + dependencyAssetsNotBuild[depAsset]++; + else + dependencyAssetsNotBuild[depAsset] = 1; + } + } + + AssetBundleBuild duplicateBuild = new AssetBundleBuild { assetBundleName = "duplicate.bundle" }; + + bundleExtraInfo[duplicateBuild.assetBundleName] = new BundleExtraInfo + { + BundleName = duplicateBuild.assetBundleName.ToLower(), + GroupName = null, + IsOptionBundle = false, + ShaderBundle = false, + IsInstallBundle = DuplicateBundleBeInstallBundle, + }; + + List duplicateAssets = new List(); + + //重复依赖资源生成打包配置 + foreach (var item in dependencyAssetsNotBuild) + { + var assetPath = item.Key; + var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + + //shader类型资源进shaderbundle,而不进duplicate.bundle + if (assetType == typeof(Shader) || assetType == typeof(ShaderVariantCollection)) + { + var shaderAsset = new Asset(assetPath); + shaderAsset.Group = shaderGroup; + shaderAsset.BundleName = "ShaderFromSVC_Together.bundle".ToLower(); + assetsToBuild[assetPath] = shaderAsset; + continue; + } + + if (item.Value == 1) continue; //只有一次依赖的跳过 + duplicateAssets.Add(assetPath); + } + duplicateBuild.assetNames = duplicateAssets.ToArray(); + return new List { duplicateBuild }; + } + + private Dictionary CollectAssetsToBuild(out BuildEntity shaderGroup) + { + Dictionary assetsToBuild = new Dictionary(); + int totalCount = Groups.Count; + int step = 0; + foreach (var group in Groups) + { + EditorUtility.DisplayProgressBar($"收集打包资源{step}/{totalCount}", $"{group.GroupName}", step * 1f / totalCount); group.OnHandleAsset = (asset) => { EditorUtility.DisplayProgressBar($"收集打包资源{step}/{totalCount}", $"{asset.FullName}@{group.GroupName}", step * 1f / totalCount); }; - group.CollectionAsset(assetsToBuild); - step++; - } - - shaderGroup = new BuildEntity(); - shaderGroup.OptionBundle = false; - shaderGroup.FolderList = new List(); - shaderGroup.BuildMode = BuildEntity.EnumBuildMode.PackTogether; - shaderGroup.GroupName = "ShaderFromSVC"; - shaderGroup.ShaderBundle = true; - shaderGroup.InstallReady = ShaderBundleBeInstallBundle; - if (SVC != null) - { - var path = AssetDatabase.GetAssetPath(SVC); - foreach (var depPath in AssetDatabase.GetDependencies(path)) - { - var depAssetType = AssetDatabase.GetMainAssetTypeAtPath(depPath); - if (depAssetType == typeof(Shader) || depAssetType == typeof(ShaderVariantCollection)) - { - var asset = new Asset(depPath); - asset.Group = shaderGroup; - asset.BundleName = "ShaderFromSVC_Together.bundle".ToLower(); - assetsToBuild[depPath] = asset; - } - } - } - - return assetsToBuild; + group.CollectionAsset(assetsToBuild); + step++; + } + + shaderGroup = new BuildEntity(); + shaderGroup.OptionBundle = false; + shaderGroup.FolderList = new List(); + shaderGroup.BuildMode = BuildEntity.EnumBuildMode.PackTogether; + shaderGroup.GroupName = "ShaderFromSVC"; + shaderGroup.ShaderBundle = true; + shaderGroup.InstallReady = ShaderBundleBeInstallBundle; + if (SVC != null) + { + var path = AssetDatabase.GetAssetPath(SVC); + foreach (var depPath in AssetDatabase.GetDependencies(path)) + { + var depAssetType = AssetDatabase.GetMainAssetTypeAtPath(depPath); + if (depAssetType == typeof(Shader) || depAssetType == typeof(ShaderVariantCollection)) + { + var asset = new Asset(depPath); + asset.Group = shaderGroup; + asset.BundleName = "ShaderFromSVC_Together.bundle".ToLower(); + assetsToBuild[depPath] = asset; + } + } + } + + return assetsToBuild; } - } - - [Serializable] + } + + [Serializable] public class UploaderCfgDict : SerializableDictionary - { + { public string GetUploaderCfg(Type uploaderCfg) { TryGetValue(uploaderCfg.FullName, out var json); @@ -239,94 +243,94 @@ namespace VersionFlow.Runtime { this[type.FullName] = json; } - } - - public class BundleExtraInfo - { - public string BundleName { get; internal set; } - public bool IsOptionBundle { get; internal set; } - public string GroupName { get; internal set; } - public bool ShaderBundle { get; internal set; } - public Hash128 BundleHash { get; internal set; } - public bool IsInstallBundle { get; internal set; } - } - - public class BundleCompare - { - public BundleCompare(Bundle @new, Bundle old) - { - New = @new; - Old = old; - } - - public Bundle New { get; private set; } - public Bundle Old { get; private set; } - - public EnumCompare Result - { - get - { - if (Old == null) return EnumCompare.Add; - if (New == null) return EnumCompare.Delete; - if (Old.Hash == New.Hash) return EnumCompare.Same; - - return EnumCompare.Modified; - } - } - - public override string ToString() - { - var bundleName = New == null ? Old.BundleName : New.BundleName; - - switch (Result) - { - case EnumCompare.Same: return $"{bundleName} [{Old.Hash}]->[{New.Hash}]"; - case EnumCompare.Modified: return $"{bundleName} [{Old.Hash}]->[{New.Hash}]"; - case EnumCompare.Add: return $"{bundleName} []->[{New.Hash}]"; - case EnumCompare.Delete: return $"{bundleName} [{Old.Hash}]->[]"; - default: return $"{bundleName} []->[]"; - } - } - - public enum EnumCompare - { - Delete, - Add, - Modified, - Same, - } - } - - public class Asset - { - public string FullName; - public HashSet dependencyAssets; - public string BundleName { get; internal set; } - public BuildEntity Group { get; internal set; } - public Asset(string path) - { - FullName = path; - - dependencyAssets = new HashSet(); - foreach (var dependPath in AssetDatabase.GetDependencies(FullName)) - { - if (dependPath == FullName) continue; - if (dependPath.EndsWith(".cs")) continue; - - dependencyAssets.Add(dependPath); - } - } - - public override int GetHashCode() - { - return FullName.GetHashCode(); - } - - public override bool Equals(object obj) - { - return GetHashCode() == obj.GetHashCode(); - } - } - + } + + public class BundleExtraInfo + { + public string BundleName { get; internal set; } + public bool IsOptionBundle { get; internal set; } + public string GroupName { get; internal set; } + public bool ShaderBundle { get; internal set; } + public Hash128 BundleHash { get; internal set; } + public bool IsInstallBundle { get; internal set; } + } + + public class BundleCompare + { + public BundleCompare(Bundle @new, Bundle old) + { + New = @new; + Old = old; + } + + public Bundle New { get; private set; } + public Bundle Old { get; private set; } + + public EnumCompare Result + { + get + { + if (Old == null) return EnumCompare.Add; + if (New == null) return EnumCompare.Delete; + if (Old.Hash == New.Hash) return EnumCompare.Same; + + return EnumCompare.Modified; + } + } + + public override string ToString() + { + var bundleName = New == null ? Old.BundleName : New.BundleName; + + switch (Result) + { + case EnumCompare.Same: return $"{bundleName} [{Old.Hash}]->[{New.Hash}]"; + case EnumCompare.Modified: return $"{bundleName} [{Old.Hash}]->[{New.Hash}]"; + case EnumCompare.Add: return $"{bundleName} []->[{New.Hash}]"; + case EnumCompare.Delete: return $"{bundleName} [{Old.Hash}]->[]"; + default: return $"{bundleName} []->[]"; + } + } + + public enum EnumCompare + { + Delete, + Add, + Modified, + Same, + } + } + + public class Asset + { + public string FullName; + public HashSet dependencyAssets; + public string BundleName { get; internal set; } + public BuildEntity Group { get; internal set; } + public Asset(string path) + { + FullName = path; + + dependencyAssets = new HashSet(); + foreach (var dependPath in AssetDatabase.GetDependencies(FullName)) + { + if (dependPath == FullName) continue; + if (dependPath.EndsWith(".cs")) continue; + + dependencyAssets.Add(dependPath); + } + } + + public override int GetHashCode() + { + return FullName.GetHashCode(); + } + + public override bool Equals(object obj) + { + return GetHashCode() == obj.GetHashCode(); + } + } + } #endif \ No newline at end of file