From 233276593204402d2b3841948056b8b47c220552 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 21 Dec 2023 19:49:50 +0800 Subject: [PATCH] style : Code text indent format --- .../Scripts/Editor/CustomPackRule.cs | 62 +-- .../PackageComparatorWindow.cs | 230 +++++----- .../PackageImporter/PackageImporterWindow.cs | 150 +++--- .../ShaderVariantCollectionHelper.cs | 50 +- .../ShaderVariantCollectionManifest.cs | 230 +++++----- .../ShaderVariantCollector.cs | 430 +++++++++--------- .../ShaderVariantCollectorSetting.cs | 42 +- .../ShaderVariantCollectorWindow.cs | 238 +++++----- .../Runtime/GameObjectAssetReference.cs | 104 ++--- .../Runtime/LoadAssetsByTagOperation.cs | 198 ++++---- .../GameScript/Editor/Encryption.cs | 82 ++-- .../Runtime/BattleLogic/BattleRoom.cs | 374 +++++++-------- .../Runtime/BattleLogic/EntityAsteroid.cs | 52 +-- .../Runtime/BattleLogic/EntityBullet.cs | 74 +-- .../Runtime/BattleLogic/EntityEffect.cs | 18 +- .../Runtime/BattleLogic/EntityEnemy.cs | 150 +++--- .../Runtime/BattleLogic/EntityPlayer.cs | 92 ++-- .../Runtime/Behaviour/ApplicationQuit.cs | 16 +- .../Runtime/Behaviour/BackgroundScroller.cs | 24 +- .../Space Shooter/GameScript/Runtime/Boot.cs | 64 +-- .../Runtime/EventDefine/BattleEventDefine.cs | 198 ++++---- .../Runtime/EventDefine/PatchEventDefine.cs | 194 ++++---- .../Runtime/EventDefine/SceneEventDefine.cs | 32 +- .../Runtime/EventDefine/UserEventDefine.cs | 110 ++--- .../Runtime/GameLogic/GameManager.cs | 84 ++-- .../Runtime/GameLogic/SceneBattle.cs | 102 ++--- .../GameScript/Runtime/GameLogic/SceneHome.cs | 46 +- .../FsmNode/FsmClearPackageCache.cs | 46 +- .../FsmNode/FsmCreatePackageDownloader.cs | 78 ++-- .../FsmNode/FsmDownloadPackageFiles.cs | 56 +-- .../FsmNode/FsmDownloadPackageOver.cs | 30 +- .../FsmNode/FsmInitializePackage.cs | 392 ++++++++-------- .../FsmNode/FsmUpdatePackageManifest.cs | 72 +-- .../FsmNode/FsmUpdatePackageVersion.cs | 68 +-- .../PatchLogic/FsmNode/FsmUpdaterDone.cs | 24 +- .../Runtime/PatchLogic/PatchOperation.cs | 168 +++---- .../Runtime/PatchLogic/PatchWindow.cs | 324 ++++++------- .../Runtime/WindowLogic/UIAboutWindow.cs | 18 +- .../Runtime/WindowLogic/UIBattleWindow.cs | 78 ++-- .../Runtime/WindowLogic/UIHomeWindow.cs | 60 +-- .../Runtime/WindowLogic/UILoadingWindow.cs | 56 +-- .../BuildinFileManifest.cs | 2 +- .../StreamingAssetsDefine.cs | 8 +- 43 files changed, 2463 insertions(+), 2463 deletions(-) diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs index 1e34ba6..dc3c5a8 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/CustomPackRule.cs @@ -8,43 +8,43 @@ using YooAsset.Editor; [DisplayName("打包特效纹理(自定义)")] public class PackEffectTexture : IPackRule { - private const string PackDirectory = "Assets/Effect/Textures/"; + private const string PackDirectory = "Assets/Effect/Textures/"; - PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data) - { - string assetPath = data.AssetPath; - if (assetPath.StartsWith(PackDirectory) == false) - throw new Exception($"Only support folder : {PackDirectory}"); - - string assetName = Path.GetFileName(assetPath).ToLower(); - string firstChar = assetName.Substring(0, 1); - string bundleName = $"{PackDirectory}effect_texture_{firstChar}"; - var packRuleResult = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension); - return packRuleResult; - } + PackRuleResult IPackRule.GetPackRuleResult(PackRuleData data) + { + string assetPath = data.AssetPath; + if (assetPath.StartsWith(PackDirectory) == false) + throw new Exception($"Only support folder : {PackDirectory}"); + + string assetName = Path.GetFileName(assetPath).ToLower(); + string firstChar = assetName.Substring(0, 1); + string bundleName = $"{PackDirectory}effect_texture_{firstChar}"; + var packRuleResult = new PackRuleResult(bundleName, DefaultPackRule.AssetBundleFileExtension); + return packRuleResult; + } } [DisplayName("打包视频(自定义)")] public class PackVideo : IPackRule { - public PackRuleResult GetPackRuleResult(PackRuleData data) - { - string bundleName = RemoveExtension(data.AssetPath); - string fileExtension = Path.GetExtension(data.AssetPath); - fileExtension = fileExtension.Remove(0, 1); - PackRuleResult result = new PackRuleResult(bundleName, fileExtension); - return result; - } + public PackRuleResult GetPackRuleResult(PackRuleData data) + { + string bundleName = RemoveExtension(data.AssetPath); + string fileExtension = Path.GetExtension(data.AssetPath); + fileExtension = fileExtension.Remove(0, 1); + PackRuleResult result = new PackRuleResult(bundleName, fileExtension); + return result; + } - private string RemoveExtension(string str) - { - if (string.IsNullOrEmpty(str)) - return str; + private string RemoveExtension(string str) + { + if (string.IsNullOrEmpty(str)) + return str; - int index = str.LastIndexOf("."); - if (index == -1) - return str; - else - return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" - } + int index = str.LastIndexOf("."); + if (index == -1) + return str; + else + return str.Remove(index); //"assets/config/test.unity3d" --> "assets/config/test" + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageComparator/PackageComparatorWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageComparator/PackageComparatorWindow.cs index a5d85ed..d3b6728 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageComparator/PackageComparatorWindow.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageComparator/PackageComparatorWindow.cs @@ -6,133 +6,133 @@ using UnityEditor; namespace YooAsset.Editor { - public class PackageComparatorWindow : EditorWindow - { - static PackageComparatorWindow _thisInstance; - - [MenuItem("Tools/补丁包比对工具", false, 102)] - static void ShowWindow() - { - if (_thisInstance == null) - { - _thisInstance = EditorWindow.GetWindow(typeof(PackageComparatorWindow), false, "补丁包比对工具", true) as PackageComparatorWindow; - _thisInstance.minSize = new Vector2(800, 600); - } - _thisInstance.Show(); - } + public class PackageComparatorWindow : EditorWindow + { + static PackageComparatorWindow _thisInstance; + + [MenuItem("Tools/补丁包比对工具", false, 102)] + static void ShowWindow() + { + if (_thisInstance == null) + { + _thisInstance = EditorWindow.GetWindow(typeof(PackageComparatorWindow), false, "补丁包比对工具", true) as PackageComparatorWindow; + _thisInstance.minSize = new Vector2(800, 600); + } + _thisInstance.Show(); + } - private string _manifestPath1 = string.Empty; - private string _manifestPath2 = string.Empty; - private readonly List _changeList = new List(); - private readonly List _newList = new List(); - private Vector2 _scrollPos1; - private Vector2 _scrollPos2; + private string _manifestPath1 = string.Empty; + private string _manifestPath2 = string.Empty; + private readonly List _changeList = new List(); + private readonly List _newList = new List(); + private Vector2 _scrollPos1; + private Vector2 _scrollPos2; - private void OnGUI() - { - GUILayout.Space(10); - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("选择补丁包1", GUILayout.MaxWidth(150))) - { - string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); - if (string.IsNullOrEmpty(resultPath)) - return; - _manifestPath1 = resultPath; - } - EditorGUILayout.LabelField(_manifestPath1); - EditorGUILayout.EndHorizontal(); + private void OnGUI() + { + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包1", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath1 = resultPath; + } + EditorGUILayout.LabelField(_manifestPath1); + EditorGUILayout.EndHorizontal(); - GUILayout.Space(10); - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("选择补丁包2", GUILayout.MaxWidth(150))) - { - string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); - if (string.IsNullOrEmpty(resultPath)) - return; - _manifestPath2 = resultPath; - } - EditorGUILayout.LabelField(_manifestPath2); - EditorGUILayout.EndHorizontal(); + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包2", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath2 = resultPath; + } + EditorGUILayout.LabelField(_manifestPath2); + EditorGUILayout.EndHorizontal(); - if (string.IsNullOrEmpty(_manifestPath1) == false && string.IsNullOrEmpty(_manifestPath2) == false) - { - if (GUILayout.Button("比对差异", GUILayout.MaxWidth(150))) - { - ComparePackage(_changeList, _newList); - } - } + if (string.IsNullOrEmpty(_manifestPath1) == false && string.IsNullOrEmpty(_manifestPath2) == false) + { + if (GUILayout.Button("比对差异", GUILayout.MaxWidth(150))) + { + ComparePackage(_changeList, _newList); + } + } - EditorGUILayout.Space(); - using (new EditorGUI.DisabledScope(false)) - { - int totalCount = _changeList.Count; - EditorGUILayout.Foldout(true, $"差异列表 ( {totalCount} )"); + EditorGUILayout.Space(); + using (new EditorGUI.DisabledScope(false)) + { + int totalCount = _changeList.Count; + EditorGUILayout.Foldout(true, $"差异列表 ( {totalCount} )"); - EditorGUI.indentLevel = 1; - _scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1); - { - foreach (var bundle in _changeList) - { - EditorGUILayout.LabelField($"{bundle.BundleName} | {(bundle.FileSize / 1024)}K"); - } - } - EditorGUILayout.EndScrollView(); - EditorGUI.indentLevel = 0; - } + EditorGUI.indentLevel = 1; + _scrollPos1 = EditorGUILayout.BeginScrollView(_scrollPos1); + { + foreach (var bundle in _changeList) + { + EditorGUILayout.LabelField($"{bundle.BundleName} | {(bundle.FileSize / 1024)}K"); + } + } + EditorGUILayout.EndScrollView(); + EditorGUI.indentLevel = 0; + } - EditorGUILayout.Space(); - using (new EditorGUI.DisabledScope(false)) - { - int totalCount = _newList.Count; - EditorGUILayout.Foldout(true, $"新增列表 ( {totalCount} )"); + EditorGUILayout.Space(); + using (new EditorGUI.DisabledScope(false)) + { + int totalCount = _newList.Count; + EditorGUILayout.Foldout(true, $"新增列表 ( {totalCount} )"); - EditorGUI.indentLevel = 1; - _scrollPos2 = EditorGUILayout.BeginScrollView(_scrollPos2); - { - foreach (var bundle in _newList) - { - EditorGUILayout.LabelField($"{bundle.BundleName}"); - } - } - EditorGUILayout.EndScrollView(); - EditorGUI.indentLevel = 0; - } - } + EditorGUI.indentLevel = 1; + _scrollPos2 = EditorGUILayout.BeginScrollView(_scrollPos2); + { + foreach (var bundle in _newList) + { + EditorGUILayout.LabelField($"{bundle.BundleName}"); + } + } + EditorGUILayout.EndScrollView(); + EditorGUI.indentLevel = 0; + } + } - private void ComparePackage(List changeList, List newList) - { - changeList.Clear(); - newList.Clear(); + private void ComparePackage(List changeList, List newList) + { + changeList.Clear(); + newList.Clear(); - // 加载补丁清单1 - byte[] bytesData1 = FileUtility.ReadAllBytes(_manifestPath1); - PackageManifest manifest1 = ManifestTools.DeserializeFromBinary(bytesData1); + // 加载补丁清单1 + byte[] bytesData1 = FileUtility.ReadAllBytes(_manifestPath1); + PackageManifest manifest1 = ManifestTools.DeserializeFromBinary(bytesData1); - // 加载补丁清单1 - byte[] bytesData2 = FileUtility.ReadAllBytes(_manifestPath2); - PackageManifest manifest2 = ManifestTools.DeserializeFromBinary(bytesData2); + // 加载补丁清单1 + byte[] bytesData2 = FileUtility.ReadAllBytes(_manifestPath2); + PackageManifest manifest2 = ManifestTools.DeserializeFromBinary(bytesData2); - // 拷贝文件列表 - foreach (var bundle2 in manifest2.BundleList) - { - if (manifest1.TryGetPackageBundleByBundleName(bundle2.BundleName, out PackageBundle bundle1)) - { - if (bundle2.FileHash != bundle1.FileHash) - { - changeList.Add(bundle2); - } - } - else - { - newList.Add(bundle2); - } - } + // 拷贝文件列表 + foreach (var bundle2 in manifest2.BundleList) + { + if (manifest1.TryGetPackageBundleByBundleName(bundle2.BundleName, out PackageBundle bundle1)) + { + if (bundle2.FileHash != bundle1.FileHash) + { + changeList.Add(bundle2); + } + } + else + { + newList.Add(bundle2); + } + } - // 按字母重新排序 - changeList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); - newList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); + // 按字母重新排序 + changeList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); + newList.Sort((x, y) => string.Compare(x.BundleName, y.BundleName)); - Debug.Log("资源包差异比对完成!"); - } - } + Debug.Log("资源包差异比对完成!"); + } + } } diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageImporter/PackageImporterWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageImporter/PackageImporterWindow.cs index 8009f1f..690a7f8 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageImporter/PackageImporterWindow.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/PackageImporter/PackageImporterWindow.cs @@ -4,88 +4,88 @@ using UnityEditor; namespace YooAsset.Editor { - public class PackageImporterWindow : EditorWindow - { - static PackageImporterWindow _thisInstance; + public class PackageImporterWindow : EditorWindow + { + static PackageImporterWindow _thisInstance; - [MenuItem("Tools/补丁包导入工具", false, 101)] - static void ShowWindow() - { - if (_thisInstance == null) - { - _thisInstance = EditorWindow.GetWindow(typeof(PackageImporterWindow), false, "补丁包导入工具", true) as PackageImporterWindow; - _thisInstance.minSize = new Vector2(800, 600); - } - _thisInstance.Show(); - } + [MenuItem("Tools/补丁包导入工具", false, 101)] + static void ShowWindow() + { + if (_thisInstance == null) + { + _thisInstance = EditorWindow.GetWindow(typeof(PackageImporterWindow), false, "补丁包导入工具", true) as PackageImporterWindow; + _thisInstance.minSize = new Vector2(800, 600); + } + _thisInstance.Show(); + } - private string _manifestPath = string.Empty; - private string _packageName = "DefaultPackage"; + private string _manifestPath = string.Empty; + private string _packageName = "DefaultPackage"; - private void OnGUI() - { - GUILayout.Space(10); - EditorGUILayout.BeginHorizontal(); - if (GUILayout.Button("选择补丁包", GUILayout.MaxWidth(150))) - { - string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); - if (string.IsNullOrEmpty(resultPath)) - return; - _manifestPath = resultPath; - } - EditorGUILayout.LabelField(_manifestPath); - EditorGUILayout.EndHorizontal(); + private void OnGUI() + { + GUILayout.Space(10); + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("选择补丁包", GUILayout.MaxWidth(150))) + { + string resultPath = EditorUtility.OpenFilePanel("Find", "Assets/", "bytes"); + if (string.IsNullOrEmpty(resultPath)) + return; + _manifestPath = resultPath; + } + EditorGUILayout.LabelField(_manifestPath); + EditorGUILayout.EndHorizontal(); - if (string.IsNullOrEmpty(_manifestPath) == false) - { - if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150))) - { - string streamingAssetsRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); - EditorTools.ClearFolder(streamingAssetsRoot); - CopyPackageFiles(_manifestPath); - } - } - } + if (string.IsNullOrEmpty(_manifestPath) == false) + { + if (GUILayout.Button("导入补丁包(全部文件)", GUILayout.MaxWidth(150))) + { + string streamingAssetsRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); + EditorTools.ClearFolder(streamingAssetsRoot); + CopyPackageFiles(_manifestPath); + } + } + } - private void CopyPackageFiles(string manifestFilePath) - { - string manifestFileName = Path.GetFileNameWithoutExtension(manifestFilePath); - string outputDirectory = Path.GetDirectoryName(manifestFilePath); + private void CopyPackageFiles(string manifestFilePath) + { + string manifestFileName = Path.GetFileNameWithoutExtension(manifestFilePath); + string outputDirectory = Path.GetDirectoryName(manifestFilePath); - // 加载补丁清单 - byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath); - PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData); + // 加载补丁清单 + byte[] bytesData = FileUtility.ReadAllBytes(manifestFilePath); + PackageManifest manifest = ManifestTools.DeserializeFromBinary(bytesData); - // 拷贝核心文件 - { - string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes"; - EditorTools.CopyFile(sourcePath, destPath, true); - } - { - string sourcePath = $"{outputDirectory}/{manifestFileName}.hash"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash"; - EditorTools.CopyFile(sourcePath, destPath, true); - } - { - string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName); - string sourcePath = $"{outputDirectory}/{fileName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{fileName}"; - EditorTools.CopyFile(sourcePath, destPath, true); - } + // 拷贝核心文件 + { + string sourcePath = $"{outputDirectory}/{manifestFileName}.bytes"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.bytes"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + { + string sourcePath = $"{outputDirectory}/{manifestFileName}.hash"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{manifestFileName}.hash"; + EditorTools.CopyFile(sourcePath, destPath, true); + } + { + string fileName = YooAssetSettingsData.GetPackageVersionFileName(manifest.PackageName); + string sourcePath = $"{outputDirectory}/{fileName}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{fileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } - // 拷贝文件列表 - int fileCount = 0; - foreach (var packageBundle in manifest.BundleList) - { - fileCount++; - string sourcePath = $"{outputDirectory}/{packageBundle.FileName}"; - string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}"; - EditorTools.CopyFile(sourcePath, destPath, true); - } + // 拷贝文件列表 + int fileCount = 0; + foreach (var packageBundle in manifest.BundleList) + { + fileCount++; + string sourcePath = $"{outputDirectory}/{packageBundle.FileName}"; + string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsRoot()}/{_packageName}/{packageBundle.FileName}"; + EditorTools.CopyFile(sourcePath, destPath, true); + } - Debug.Log($"补丁包拷贝完成,一共拷贝了{fileCount}个资源文件"); - AssetDatabase.Refresh(); - } - } + Debug.Log($"补丁包拷贝完成,一共拷贝了{fileCount}个资源文件"); + AssetDatabase.Refresh(); + } + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs index f29c5da..7345fbf 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs @@ -9,30 +9,30 @@ using YooAsset.Editor; public static class ShaderVariantCollectionHelper { - public static void ClearCurrentShaderVariantCollection() - { - EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "ClearCurrentShaderVariantCollection"); - } - public static void SaveCurrentShaderVariantCollection(string savePath) - { - EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "SaveCurrentShaderVariantCollection", savePath); - } - public static int GetCurrentShaderVariantCollectionShaderCount() - { - return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionShaderCount"); - } - public static int GetCurrentShaderVariantCollectionVariantCount() - { - return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionVariantCount"); - } + public static void ClearCurrentShaderVariantCollection() + { + EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "ClearCurrentShaderVariantCollection"); + } + public static void SaveCurrentShaderVariantCollection(string savePath) + { + EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "SaveCurrentShaderVariantCollection", savePath); + } + public static int GetCurrentShaderVariantCollectionShaderCount() + { + return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionShaderCount"); + } + public static int GetCurrentShaderVariantCollectionVariantCount() + { + return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionVariantCount"); + } - /// - /// 获取着色器的变种总数量 - /// - public static string GetShaderVariantCount(string assetPath) - { - Shader shader = AssetDatabase.LoadAssetAtPath(assetPath); - var variantCount = EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetVariantCount", shader, true); - return variantCount.ToString(); - } + /// + /// 获取着色器的变种总数量 + /// + public static string GetShaderVariantCount(string assetPath) + { + Shader shader = AssetDatabase.LoadAssetAtPath(assetPath); + var variantCount = EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetVariantCount", shader, true); + return variantCount.ToString(); + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs index d8a6298..73f7b78 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs @@ -10,137 +10,137 @@ using UnityEditor; [Serializable] public class ShaderVariantCollectionManifest { - [Serializable] - public class ShaderVariantElement - { - /// - /// Pass type to use in this variant. - /// - public PassType PassType; + [Serializable] + public class ShaderVariantElement + { + /// + /// Pass type to use in this variant. + /// + public PassType PassType; - /// - /// Array of shader keywords to use in this variant. - /// - public string[] Keywords; - } + /// + /// Array of shader keywords to use in this variant. + /// + public string[] Keywords; + } - [Serializable] - public class ShaderVariantInfo - { - /// - /// 着色器资源路径. - /// - public string AssetPath; + [Serializable] + public class ShaderVariantInfo + { + /// + /// 着色器资源路径. + /// + public string AssetPath; - /// - /// 着色器名称 - /// - public string ShaderName; + /// + /// 着色器名称 + /// + public string ShaderName; - /// - /// 着色器变种总数 - /// - public int ShaderVariantCount = 0; + /// + /// 着色器变种总数 + /// + public int ShaderVariantCount = 0; - /// - /// 着色器变种列表 - /// - public List ShaderVariantElements = new List(1000); - } + /// + /// 着色器变种列表 + /// + public List ShaderVariantElements = new List(1000); + } - /// - /// Number of shaders in this collection - /// - public int ShaderTotalCount; + /// + /// Number of shaders in this collection + /// + public int ShaderTotalCount; - /// - /// Number of total varians in this collection - /// - public int VariantTotalCount; + /// + /// Number of total varians in this collection + /// + public int VariantTotalCount; - /// - /// Shader variants info list. - /// - public List ShaderVariantInfos = new List(1000); + /// + /// Shader variants info list. + /// + public List ShaderVariantInfos = new List(1000); - /// - /// 添加着色器变种信息 - /// - public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords) - { - var info = GetOrCreateShaderVariantInfo(assetPath, shaderName); - ShaderVariantElement element = new ShaderVariantElement(); - element.PassType = passType; - element.Keywords = keywords; - info.ShaderVariantElements.Add(element); - info.ShaderVariantCount++; - } - private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName) - { - var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList(); - if (selectList.Count == 0) - { - ShaderVariantInfo newInfo = new ShaderVariantInfo(); - newInfo.AssetPath = assetPath; - newInfo.ShaderName = shaderName; - ShaderVariantInfos.Add(newInfo); - return newInfo; - } + /// + /// 添加着色器变种信息 + /// + public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords) + { + var info = GetOrCreateShaderVariantInfo(assetPath, shaderName); + ShaderVariantElement element = new ShaderVariantElement(); + element.PassType = passType; + element.Keywords = keywords; + info.ShaderVariantElements.Add(element); + info.ShaderVariantCount++; + } + private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName) + { + var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList(); + if (selectList.Count == 0) + { + ShaderVariantInfo newInfo = new ShaderVariantInfo(); + newInfo.AssetPath = assetPath; + newInfo.ShaderName = shaderName; + ShaderVariantInfos.Add(newInfo); + return newInfo; + } - if (selectList.Count != 1) - throw new Exception("Should never get here !"); + if (selectList.Count != 1) + throw new Exception("Should never get here !"); - return selectList[0]; - } + return selectList[0]; + } - /// - /// 解析SVC文件并将数据写入到清单 - /// - public static ShaderVariantCollectionManifest Extract(ShaderVariantCollection svc) - { - var manifest = new ShaderVariantCollectionManifest(); - manifest.ShaderTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount(); - manifest.VariantTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount(); + /// + /// 解析SVC文件并将数据写入到清单 + /// + public static ShaderVariantCollectionManifest Extract(ShaderVariantCollection svc) + { + var manifest = new ShaderVariantCollectionManifest(); + manifest.ShaderTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount(); + manifest.VariantTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount(); - using (var so = new SerializedObject(svc)) - { - var shaderArray = so.FindProperty("m_Shaders.Array"); - if (shaderArray != null && shaderArray.isArray) - { - for (int i = 0; i < shaderArray.arraySize; ++i) - { - var shaderRef = shaderArray.FindPropertyRelative($"data[{i}].first"); - var shaderVariantsArray = shaderArray.FindPropertyRelative($"data[{i}].second.variants"); - if (shaderRef != null && shaderRef.propertyType == SerializedPropertyType.ObjectReference && shaderVariantsArray != null && shaderVariantsArray.isArray) - { - var shader = shaderRef.objectReferenceValue as Shader; - if (shader == null) - { - throw new Exception("Invalid shader in ShaderVariantCollection file."); - } + using (var so = new SerializedObject(svc)) + { + var shaderArray = so.FindProperty("m_Shaders.Array"); + if (shaderArray != null && shaderArray.isArray) + { + for (int i = 0; i < shaderArray.arraySize; ++i) + { + var shaderRef = shaderArray.FindPropertyRelative($"data[{i}].first"); + var shaderVariantsArray = shaderArray.FindPropertyRelative($"data[{i}].second.variants"); + if (shaderRef != null && shaderRef.propertyType == SerializedPropertyType.ObjectReference && shaderVariantsArray != null && shaderVariantsArray.isArray) + { + var shader = shaderRef.objectReferenceValue as Shader; + if (shader == null) + { + throw new Exception("Invalid shader in ShaderVariantCollection file."); + } - string shaderAssetPath = AssetDatabase.GetAssetPath(shader); - string shaderName = shader.name; + string shaderAssetPath = AssetDatabase.GetAssetPath(shader); + string shaderName = shader.name; - // 添加变种信息 - for (int j = 0; j < shaderVariantsArray.arraySize; ++j) - { - var propKeywords = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].keywords"); - var propPassType = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].passType"); - if (propKeywords != null && propPassType != null && propKeywords.propertyType == SerializedPropertyType.String) - { - string[] keywords = propKeywords.stringValue.Split(' '); - PassType pathType = (PassType)propPassType.intValue; - manifest.AddShaderVariant(shaderAssetPath, shaderName, pathType, keywords); - } - } - } - } - } - } + // 添加变种信息 + for (int j = 0; j < shaderVariantsArray.arraySize; ++j) + { + var propKeywords = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].keywords"); + var propPassType = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].passType"); + if (propKeywords != null && propPassType != null && propKeywords.propertyType == SerializedPropertyType.String) + { + string[] keywords = propKeywords.stringValue.Split(' '); + PassType pathType = (PassType)propPassType.intValue; + manifest.AddShaderVariant(shaderAssetPath, shaderName, pathType, keywords); + } + } + } + } + } + } - return manifest; - } + return manifest; + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollector.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollector.cs index 2ad5bff..40fe733 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollector.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollector.cs @@ -11,246 +11,246 @@ using Debug = UnityEngine.Debug; public static class ShaderVariantCollector { - private enum ESteps - { - None, - Prepare, - CollectAllMaterial, - CollectVariants, - CollectSleeping, - WaitingDone, - } + private enum ESteps + { + None, + Prepare, + CollectAllMaterial, + CollectVariants, + CollectSleeping, + WaitingDone, + } - private const float WaitMilliseconds = 1000f; - private const float SleepMilliseconds = 100f; - private static string _savePath; - private static string _packageName; - private static int _processMaxNum; - private static Action _completedCallback; + private const float WaitMilliseconds = 1000f; + private const float SleepMilliseconds = 100f; + private static string _savePath; + private static string _packageName; + private static int _processMaxNum; + private static Action _completedCallback; - private static ESteps _steps = ESteps.None; - private static Stopwatch _elapsedTime; - private static List _allMaterials; - private static List _allSpheres = new List(1000); + private static ESteps _steps = ESteps.None; + private static Stopwatch _elapsedTime; + private static List _allMaterials; + private static List _allSpheres = new List(1000); - /// - /// 开始收集 - /// - public static void Run(string savePath, string packageName, int processMaxNum, Action completedCallback) - { - if (_steps != ESteps.None) - return; + /// + /// 开始收集 + /// + public static void Run(string savePath, string packageName, int processMaxNum, Action completedCallback) + { + if (_steps != ESteps.None) + return; - if (Path.HasExtension(savePath) == false) - savePath = $"{savePath}.shadervariants"; - if (Path.GetExtension(savePath) != ".shadervariants") - throw new System.Exception("Shader variant file extension is invalid."); - if (string.IsNullOrEmpty(packageName)) - throw new System.Exception("Package name is null or empty !"); + if (Path.HasExtension(savePath) == false) + savePath = $"{savePath}.shadervariants"; + if (Path.GetExtension(savePath) != ".shadervariants") + throw new System.Exception("Shader variant file extension is invalid."); + if (string.IsNullOrEmpty(packageName)) + throw new System.Exception("Package name is null or empty !"); - // 注意:先删除再保存,否则ShaderVariantCollection内容将无法及时刷新 - AssetDatabase.DeleteAsset(savePath); - EditorTools.CreateFileDirectory(savePath); - _savePath = savePath; - _packageName = packageName; - _processMaxNum = processMaxNum; - _completedCallback = completedCallback; + // 注意:先删除再保存,否则ShaderVariantCollection内容将无法及时刷新 + AssetDatabase.DeleteAsset(savePath); + EditorTools.CreateFileDirectory(savePath); + _savePath = savePath; + _packageName = packageName; + _processMaxNum = processMaxNum; + _completedCallback = completedCallback; - // 聚焦到游戏窗口 - EditorTools.FocusUnityGameWindow(); + // 聚焦到游戏窗口 + EditorTools.FocusUnityGameWindow(); - // 创建临时测试场景 - CreateTempScene(); + // 创建临时测试场景 + CreateTempScene(); - _steps = ESteps.Prepare; - EditorApplication.update += EditorUpdate; - } + _steps = ESteps.Prepare; + EditorApplication.update += EditorUpdate; + } - private static void EditorUpdate() - { - if (_steps == ESteps.None) - return; + private static void EditorUpdate() + { + if (_steps == ESteps.None) + return; - if (_steps == ESteps.Prepare) - { - ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection(); - _steps = ESteps.CollectAllMaterial; - return; //等待一帧 - } + if (_steps == ESteps.Prepare) + { + ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection(); + _steps = ESteps.CollectAllMaterial; + return; //等待一帧 + } - if (_steps == ESteps.CollectAllMaterial) - { - _allMaterials = GetAllMaterials(); - _steps = ESteps.CollectVariants; - return; //等待一帧 - } + if (_steps == ESteps.CollectAllMaterial) + { + _allMaterials = GetAllMaterials(); + _steps = ESteps.CollectVariants; + return; //等待一帧 + } - if (_steps == ESteps.CollectVariants) - { - int count = Mathf.Min(_processMaxNum, _allMaterials.Count); - List range = _allMaterials.GetRange(0, count); - _allMaterials.RemoveRange(0, count); - CollectVariants(range); + if (_steps == ESteps.CollectVariants) + { + int count = Mathf.Min(_processMaxNum, _allMaterials.Count); + List range = _allMaterials.GetRange(0, count); + _allMaterials.RemoveRange(0, count); + CollectVariants(range); - if (_allMaterials.Count > 0) - { - _elapsedTime = Stopwatch.StartNew(); - _steps = ESteps.CollectSleeping; - } - else - { - _elapsedTime = Stopwatch.StartNew(); - _steps = ESteps.WaitingDone; - } - } + if (_allMaterials.Count > 0) + { + _elapsedTime = Stopwatch.StartNew(); + _steps = ESteps.CollectSleeping; + } + else + { + _elapsedTime = Stopwatch.StartNew(); + _steps = ESteps.WaitingDone; + } + } - if (_steps == ESteps.CollectSleeping) - { - if (_elapsedTime.ElapsedMilliseconds > SleepMilliseconds) - { - DestroyAllSpheres(); - _elapsedTime.Stop(); - _steps = ESteps.CollectVariants; - } - } + if (_steps == ESteps.CollectSleeping) + { + if (_elapsedTime.ElapsedMilliseconds > SleepMilliseconds) + { + DestroyAllSpheres(); + _elapsedTime.Stop(); + _steps = ESteps.CollectVariants; + } + } - if (_steps == ESteps.WaitingDone) - { - // 注意:一定要延迟保存才会起效 - if (_elapsedTime.ElapsedMilliseconds > WaitMilliseconds) - { - _elapsedTime.Stop(); - _steps = ESteps.None; + if (_steps == ESteps.WaitingDone) + { + // 注意:一定要延迟保存才会起效 + if (_elapsedTime.ElapsedMilliseconds > WaitMilliseconds) + { + _elapsedTime.Stop(); + _steps = ESteps.None; - // 保存结果并创建清单 - ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_savePath); - CreateManifest(); + // 保存结果并创建清单 + ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_savePath); + CreateManifest(); - Debug.Log($"搜集SVC完毕!"); - EditorApplication.update -= EditorUpdate; - _completedCallback?.Invoke(); - } - } - } - private static void CreateTempScene() - { - EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); - } - private static List GetAllMaterials() - { - int progressValue = 0; - List allAssets = new List(1000); + Debug.Log($"搜集SVC完毕!"); + EditorApplication.update -= EditorUpdate; + _completedCallback?.Invoke(); + } + } + } + private static void CreateTempScene() + { + EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects); + } + private static List GetAllMaterials() + { + int progressValue = 0; + List allAssets = new List(1000); - // 获取所有打包的资源 - CollectResult collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(EBuildMode.DryRunBuild, _packageName); - foreach (var assetInfo in collectResult.CollectAssets) - { - string[] depends = AssetDatabase.GetDependencies(assetInfo.AssetPath, true); - foreach (var dependAsset in depends) - { - if (allAssets.Contains(dependAsset) == false) - allAssets.Add(dependAsset); - } - EditorTools.DisplayProgressBar("获取所有打包资源", ++progressValue, collectResult.CollectAssets.Count); - } - EditorTools.ClearProgressBar(); + // 获取所有打包的资源 + CollectResult collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(EBuildMode.DryRunBuild, _packageName); + foreach (var assetInfo in collectResult.CollectAssets) + { + string[] depends = AssetDatabase.GetDependencies(assetInfo.AssetPath, true); + foreach (var dependAsset in depends) + { + if (allAssets.Contains(dependAsset) == false) + allAssets.Add(dependAsset); + } + EditorTools.DisplayProgressBar("获取所有打包资源", ++progressValue, collectResult.CollectAssets.Count); + } + EditorTools.ClearProgressBar(); - // 搜集所有材质球 - progressValue = 0; - List allMaterial = new List(1000); - foreach (var assetPath in allAssets) - { - System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); - if (assetType == typeof(UnityEngine.Material)) - { - allMaterial.Add(assetPath); - } - EditorTools.DisplayProgressBar("搜集所有材质球", ++progressValue, allAssets.Count); - } - EditorTools.ClearProgressBar(); + // 搜集所有材质球 + progressValue = 0; + List allMaterial = new List(1000); + foreach (var assetPath in allAssets) + { + System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath); + if (assetType == typeof(UnityEngine.Material)) + { + allMaterial.Add(assetPath); + } + EditorTools.DisplayProgressBar("搜集所有材质球", ++progressValue, allAssets.Count); + } + EditorTools.ClearProgressBar(); - // 返回结果 - return allMaterial; - } - private static void CollectVariants(List materials) - { - Camera camera = Camera.main; - if (camera == null) - throw new System.Exception("Not found main camera."); + // 返回结果 + return allMaterial; + } + private static void CollectVariants(List materials) + { + Camera camera = Camera.main; + if (camera == null) + throw new System.Exception("Not found main camera."); - // 设置主相机 - float aspect = camera.aspect; - int totalMaterials = materials.Count; - float height = Mathf.Sqrt(totalMaterials / aspect) + 1; - float width = Mathf.Sqrt(totalMaterials / aspect) * aspect + 1; - float halfHeight = Mathf.CeilToInt(height / 2f); - float halfWidth = Mathf.CeilToInt(width / 2f); - camera.orthographic = true; - camera.orthographicSize = halfHeight; - camera.transform.position = new Vector3(0f, 0f, -10f); + // 设置主相机 + float aspect = camera.aspect; + int totalMaterials = materials.Count; + float height = Mathf.Sqrt(totalMaterials / aspect) + 1; + float width = Mathf.Sqrt(totalMaterials / aspect) * aspect + 1; + float halfHeight = Mathf.CeilToInt(height / 2f); + float halfWidth = Mathf.CeilToInt(width / 2f); + camera.orthographic = true; + camera.orthographicSize = halfHeight; + camera.transform.position = new Vector3(0f, 0f, -10f); - // 创建测试球体 - int xMax = (int)(width - 1); - int x = 0, y = 0; - int progressValue = 0; - for (int i = 0; i < materials.Count; i++) - { - var material = materials[i]; - var position = new Vector3(x - halfWidth + 1f, y - halfHeight + 1f, 0f); - var go = CreateSphere(material, position, i); - if (go != null) - _allSpheres.Add(go); - if (x == xMax) - { - x = 0; - y++; - } - else - { - x++; - } - EditorTools.DisplayProgressBar("照射所有材质球", ++progressValue, materials.Count); - } - EditorTools.ClearProgressBar(); - } - private static GameObject CreateSphere(string assetPath, Vector3 position, int index) - { - var material = AssetDatabase.LoadAssetAtPath(assetPath); - var shader = material.shader; - if (shader == null) - return null; + // 创建测试球体 + int xMax = (int)(width - 1); + int x = 0, y = 0; + int progressValue = 0; + for (int i = 0; i < materials.Count; i++) + { + var material = materials[i]; + var position = new Vector3(x - halfWidth + 1f, y - halfHeight + 1f, 0f); + var go = CreateSphere(material, position, i); + if (go != null) + _allSpheres.Add(go); + if (x == xMax) + { + x = 0; + y++; + } + else + { + x++; + } + EditorTools.DisplayProgressBar("照射所有材质球", ++progressValue, materials.Count); + } + EditorTools.ClearProgressBar(); + } + private static GameObject CreateSphere(string assetPath, Vector3 position, int index) + { + var material = AssetDatabase.LoadAssetAtPath(assetPath); + var shader = material.shader; + if (shader == null) + return null; - var go = GameObject.CreatePrimitive(PrimitiveType.Sphere); - go.GetComponent().sharedMaterial = material; - go.transform.position = position; - go.name = $"Sphere_{index} | {material.name}"; - return go; - } - private static void DestroyAllSpheres() - { - foreach (var go in _allSpheres) - { - GameObject.DestroyImmediate(go); - } - _allSpheres.Clear(); + var go = GameObject.CreatePrimitive(PrimitiveType.Sphere); + go.GetComponent().sharedMaterial = material; + go.transform.position = position; + go.name = $"Sphere_{index} | {material.name}"; + return go; + } + private static void DestroyAllSpheres() + { + foreach (var go in _allSpheres) + { + GameObject.DestroyImmediate(go); + } + _allSpheres.Clear(); - // 尝试释放编辑器加载的资源 - EditorUtility.UnloadUnusedAssetsImmediate(true); - } - private static void CreateManifest() - { - AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); + // 尝试释放编辑器加载的资源 + EditorUtility.UnloadUnusedAssetsImmediate(true); + } + private static void CreateManifest() + { + AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); - ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath(_savePath); - if (svc != null) - { - var wrapper = ShaderVariantCollectionManifest.Extract(svc); - string jsonData = JsonUtility.ToJson(wrapper, true); - string savePath = _savePath.Replace(".shadervariants", ".json"); - File.WriteAllText(savePath, jsonData); - } + ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath(_savePath); + if (svc != null) + { + var wrapper = ShaderVariantCollectionManifest.Extract(svc); + string jsonData = JsonUtility.ToJson(wrapper, true); + string savePath = _savePath.Replace(".shadervariants", ".json"); + File.WriteAllText(savePath, jsonData); + } - AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); - } + AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs index 30d8c4f..62fecc0 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs @@ -3,27 +3,27 @@ using UnityEditor; public class ShaderVariantCollectorSetting : ScriptableObject { - private const string DefaultSavePath = "Assets/MyShaderVariants.shadervariants"; + private const string DefaultSavePath = "Assets/MyShaderVariants.shadervariants"; - public static string GeFileSavePath(string packageName) - { - string key = $"{Application.productName}_{packageName}_GeFileSavePath"; - return EditorPrefs.GetString(key, DefaultSavePath); - } - public static void SetFileSavePath(string packageName, string savePath) - { - string key = $"{Application.productName}_{packageName}_GeFileSavePath"; - EditorPrefs.SetString(key, savePath); - } + public static string GeFileSavePath(string packageName) + { + string key = $"{Application.productName}_{packageName}_GeFileSavePath"; + return EditorPrefs.GetString(key, DefaultSavePath); + } + public static void SetFileSavePath(string packageName, string savePath) + { + string key = $"{Application.productName}_{packageName}_GeFileSavePath"; + EditorPrefs.SetString(key, savePath); + } - public static int GeProcessCapacity(string packageName) - { - string key = $"{Application.productName}_{packageName}_GeProcessCapacity"; - return EditorPrefs.GetInt(key, 1000); - } - public static void SetProcessCapacity(string packageName, int capacity) - { - string key = $"{Application.productName}_{packageName}_GeProcessCapacity"; - EditorPrefs.SetInt(key, capacity); - } + public static int GeProcessCapacity(string packageName) + { + string key = $"{Application.productName}_{packageName}_GeProcessCapacity"; + return EditorPrefs.GetInt(key, 1000); + } + public static void SetProcessCapacity(string packageName, int capacity) + { + string key = $"{Application.productName}_{packageName}_GeProcessCapacity"; + EditorPrefs.SetInt(key, capacity); + } } \ No newline at end of file diff --git a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs index e33f74d..1120d61 100644 --- a/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs +++ b/Assets/YooAsset/Samples~/Extension Sample/Scripts/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs @@ -10,141 +10,141 @@ using YooAsset.Editor; public class ShaderVariantCollectorWindow : EditorWindow { - [MenuItem("Tools/着色器变种收集器", false, 100)] - public static void OpenWindow() - { - ShaderVariantCollectorWindow window = GetWindow("着色器变种收集工具", true); - window.minSize = new Vector2(800, 600); - } + [MenuItem("Tools/着色器变种收集器", false, 100)] + public static void OpenWindow() + { + ShaderVariantCollectorWindow window = GetWindow("着色器变种收集工具", true); + window.minSize = new Vector2(800, 600); + } - private Button _collectButton; - private TextField _collectOutputField; - private Label _currentShaderCountField; - private Label _currentVariantCountField; - private SliderInt _processCapacitySlider; - private PopupField _packageField; + private Button _collectButton; + private TextField _collectOutputField; + private Label _currentShaderCountField; + private Label _currentVariantCountField; + private SliderInt _processCapacitySlider; + private PopupField _packageField; - private List _packageNames; - private string _currentPackageName; + private List _packageNames; + private string _currentPackageName; - public void CreateGUI() - { - try - { - VisualElement root = this.rootVisualElement; + public void CreateGUI() + { + try + { + VisualElement root = this.rootVisualElement; - // 加载布局文件 - var visualAsset = UxmlLoader.LoadWindowUXML(); - if (visualAsset == null) - return; + // 加载布局文件 + var visualAsset = UxmlLoader.LoadWindowUXML(); + if (visualAsset == null) + return; - visualAsset.CloneTree(root); + visualAsset.CloneTree(root); - // 包裹名称列表 - _packageNames = GetBuildPackageNames(); - _currentPackageName = _packageNames[0]; + // 包裹名称列表 + _packageNames = GetBuildPackageNames(); + _currentPackageName = _packageNames[0]; - // 文件输出目录 - _collectOutputField = root.Q("CollectOutput"); - _collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeFileSavePath(_currentPackageName)); - _collectOutputField.RegisterValueChangedCallback(evt => - { - ShaderVariantCollectorSetting.SetFileSavePath(_currentPackageName, _collectOutputField.value); - }); + // 文件输出目录 + _collectOutputField = root.Q("CollectOutput"); + _collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeFileSavePath(_currentPackageName)); + _collectOutputField.RegisterValueChangedCallback(evt => + { + ShaderVariantCollectorSetting.SetFileSavePath(_currentPackageName, _collectOutputField.value); + }); - // 收集的包裹 - var packageContainer = root.Q("PackageContainer"); - if (_packageNames.Count > 0) - { - int defaultIndex = GetDefaultPackageIndex(_currentPackageName); - _packageField = new PopupField(_packageNames, defaultIndex); - _packageField.label = "Package"; - _packageField.style.width = 350; - _packageField.RegisterValueChangedCallback(evt => - { - _currentPackageName = _packageField.value; - }); - packageContainer.Add(_packageField); - } - else - { - _packageField = new PopupField(); - _packageField.label = "Package"; - _packageField.style.width = 350; - packageContainer.Add(_packageField); - } + // 收集的包裹 + var packageContainer = root.Q("PackageContainer"); + if (_packageNames.Count > 0) + { + int defaultIndex = GetDefaultPackageIndex(_currentPackageName); + _packageField = new PopupField(_packageNames, defaultIndex); + _packageField.label = "Package"; + _packageField.style.width = 350; + _packageField.RegisterValueChangedCallback(evt => + { + _currentPackageName = _packageField.value; + }); + packageContainer.Add(_packageField); + } + else + { + _packageField = new PopupField(); + _packageField.label = "Package"; + _packageField.style.width = 350; + packageContainer.Add(_packageField); + } - // 容器值 - _processCapacitySlider = root.Q("ProcessCapacity"); - _processCapacitySlider.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeProcessCapacity(_currentPackageName)); + // 容器值 + _processCapacitySlider = root.Q("ProcessCapacity"); + _processCapacitySlider.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeProcessCapacity(_currentPackageName)); #if !UNITY_2020_3_OR_NEWER - _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; - _processCapacitySlider.RegisterValueChangedCallback(evt => - { - ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); - _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; - }); + _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; + _processCapacitySlider.RegisterValueChangedCallback(evt => + { + ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); + _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; + }); #else - _processCapacitySlider.RegisterValueChangedCallback(evt => - { - ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); - }); + _processCapacitySlider.RegisterValueChangedCallback(evt => + { + ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); + }); #endif - _currentShaderCountField = root.Q