From 3de44a416c2a741a1fd564d541d809e100f29da6 Mon Sep 17 00:00:00 2001 From: hevinci Date: Thu, 28 Apr 2022 23:29:15 +0800 Subject: [PATCH] YooAssetSetting folder search location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YooAssetSetting文件夹全路径搜索定位 --- .../AssetBundleBuilderSettingData.cs | 9 +-- .../AssetBundleBuilderWindow.cs | 2 +- .../AssetBundleDebuggerWindow.cs | 2 +- .../VisualViewers/AssetListDebuggerViewer.cs | 2 +- .../VisualViewers/BundleListDebuggerViewer.cs | 2 +- .../AssetBundleGrouperSettingData.cs | 9 +-- .../AssetBundleGrouperWindow.cs | 2 +- .../AssetBundleReporterWindow.cs | 2 +- .../VisualViewers/AssetListReporterViewer.cs | 2 +- .../VisualViewers/BundleListReporterViewer.cs | 2 +- .../VisualViewers/SummaryReporterViewer.cs | 2 +- Assets/YooAsset/Editor/EditorDefine.cs | 40 ++++---------- Assets/YooAsset/Editor/EditorTools.cs | 55 +++++++++++++++---- .../ShaderVariantCollectorSettingData.cs | 9 +-- 14 files changed, 80 insertions(+), 60 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSettingData.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSettingData.cs index 31e51f9..b1ca04c 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSettingData.cs @@ -25,13 +25,14 @@ namespace YooAsset.Editor private static void LoadSettingData() { // 加载配置文件 - _setting = AssetDatabase.LoadAssetAtPath(EditorDefine.AssetBundleBuilderSettingFilePath); + string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleBuilderSetting)}.asset"; + _setting = AssetDatabase.LoadAssetAtPath(settingFilePath); if (_setting == null) { - Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {EditorDefine.AssetBundleBuilderSettingFilePath}"); + Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {settingFilePath}"); _setting = ScriptableObject.CreateInstance(); - EditorTools.CreateFileDirectory(EditorDefine.AssetBundleBuilderSettingFilePath); - AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleBuilderSettingFilePath); + EditorTools.CreateFileDirectory(settingFilePath); + AssetDatabase.CreateAsset(Setting, settingFilePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index aef52a2..6e87bf9 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -37,7 +37,7 @@ namespace YooAsset.Editor VisualElement root = this.rootVisualElement; // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml"; var visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs index e457939..04327e8 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs @@ -50,7 +50,7 @@ namespace YooAsset.Editor VisualElement root = rootVisualElement; // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml"; var visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs index 6021e82..ae6cb6d 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/AssetListDebuggerViewer.cs @@ -24,7 +24,7 @@ namespace YooAsset.Editor public void InitViewer() { // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml"; _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (_visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/BundleListDebuggerViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/BundleListDebuggerViewer.cs index 733cb7d..0cb4a78 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/BundleListDebuggerViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/BundleListDebuggerViewer.cs @@ -24,7 +24,7 @@ namespace YooAsset.Editor public void InitViewer() { // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml"; _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (_visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs index ee4a9d9..4022498 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperSettingData.cs @@ -106,13 +106,14 @@ namespace YooAsset.Editor private static void LoadSettingData() { // 加载配置文件 - _setting = AssetDatabase.LoadAssetAtPath(EditorDefine.AssetBundleGrouperSettingFilePath); + string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleGrouperSetting)}.asset"; + _setting = AssetDatabase.LoadAssetAtPath(settingFilePath); if (_setting == null) { - Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {EditorDefine.AssetBundleGrouperSettingFilePath}"); + Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {settingFilePath}"); _setting = ScriptableObject.CreateInstance(); - EditorTools.CreateFileDirectory(EditorDefine.AssetBundleGrouperSettingFilePath); - AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleGrouperSettingFilePath); + EditorTools.CreateFileDirectory(settingFilePath); + AssetDatabase.CreateAsset(Setting, settingFilePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } diff --git a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs index 58051c2..2b511c9 100644 --- a/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleGrouper/AssetBundleGrouperWindow.cs @@ -43,7 +43,7 @@ namespace YooAsset.Editor _filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames(); // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml"; var visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs index 394bba0..c08da5b 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/AssetBundleReporterWindow.cs @@ -51,7 +51,7 @@ namespace YooAsset.Editor VisualElement root = this.rootVisualElement; // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml"; var visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs index ca5b72d..eedf7ce 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/AssetListReporterViewer.cs @@ -30,7 +30,7 @@ namespace YooAsset.Editor public void InitViewer() { // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml"; _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (_visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/BundleListReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/BundleListReporterViewer.cs index 34bd09b..eec9de5 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/BundleListReporterViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/BundleListReporterViewer.cs @@ -32,7 +32,7 @@ namespace YooAsset.Editor public void InitViewer() { // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml"; _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (_visualAsset == null) diff --git a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs index e07f987..e9839e7 100644 --- a/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleReporter/VisualViewers/SummaryReporterViewer.cs @@ -37,7 +37,7 @@ namespace YooAsset.Editor public void InitViewer() { // 加载布局文件 - string rootPath = EditorTools.GetYooAssetPath(); + string rootPath = EditorTools.GetYooAssetSourcePath(); string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml"; _visualAsset = AssetDatabase.LoadAssetAtPath(uxml); if (_visualAsset == null) diff --git a/Assets/YooAsset/Editor/EditorDefine.cs b/Assets/YooAsset/Editor/EditorDefine.cs index 79b729b..a04631e 100644 --- a/Assets/YooAsset/Editor/EditorDefine.cs +++ b/Assets/YooAsset/Editor/EditorDefine.cs @@ -1,25 +1,9 @@ - -using System; +using System; namespace YooAsset.Editor { public class EditorDefine { - /// - /// 资源包构建工具的配置文件存储路径 - /// - public const string AssetBundleBuilderSettingFilePath = "Assets/YooAssetSetting/AssetBundleBuilderSetting.asset"; - - /// - /// 资源包分组工具的配置文件存储路径 - /// - public const string AssetBundleGrouperSettingFilePath = "Assets/YooAssetSetting/AssetBundleGrouperSetting.asset"; - - /// - /// 着色器变种收集工具的配置文件存储路径 - /// - public const string ShaderVariantCollectorSettingFilePath = "Assets/YooAssetSetting/ShaderVariantCollectorSetting.asset"; - /// /// 停靠窗口类型集合 /// @@ -55,16 +39,16 @@ namespace YooAsset.Editor /// public enum EAssetFileExtension { - prefab, //预制体 - unity, //场景 - fbx, //模型 - anim, //动画 - controller, //控制器 - png, //图片 - jpg, //图片 - mat, //材质球 - shader, //着色器 - ttf, //字体 - cs, //脚本 + prefab, + unity, + fbx, + anim, + controller, + png, + jpg, + mat, + shader, + ttf, + cs, } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index 9b466db..dd9cd39 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -412,7 +412,8 @@ namespace YooAsset.Editor #endregion #region 路径 - private static string YooAssetPath; + private static string YooAssetSourcePath; + private static string YooAssetSettingPath; /// /// 获取规范的路径 @@ -423,27 +424,30 @@ namespace YooAsset.Editor } /// - /// 获取资源框架目录路径 + /// 获取资源框架源码路径 /// - public static string GetYooAssetPath() + public static string GetYooAssetSourcePath() { - if (string.IsNullOrEmpty(YooAssetPath) == false) - return YooAssetPath; + if (string.IsNullOrEmpty(YooAssetSourcePath) == false) + { + if (Directory.Exists(YooAssetSourcePath)) + return YooAssetSourcePath; + } // 从Pakcages目录下搜索 - string packagesPath = ("Packages/com.tuyoogame.yooasset/README.md"); + string packagesPath = "Packages/com.tuyoogame.yooasset/README.md"; var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset)); if (obj != null) { - YooAssetPath = "Packages/com.tuyoogame.yooasset/"; - return YooAssetPath; + YooAssetSourcePath = "Packages/com.tuyoogame.yooasset/"; + return YooAssetSourcePath; } // 从Assets目录下搜索 string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories); if (allDirectorys.Length == 0) { - Debug.LogError("Not found YooAsset Package !"); + Debug.LogError("Not found YooAsset package !"); return string.Empty; } @@ -463,8 +467,37 @@ namespace YooAsset.Editor return string.Empty; } - YooAssetPath = AbsolutePathToAssetPath(targetDirectory); - return YooAssetPath; + YooAssetSourcePath = AbsolutePathToAssetPath(targetDirectory); + return YooAssetSourcePath; + } + + /// + /// 获取资源框架配置路径 + /// + public static string GetYooAssetSettingPath() + { + if (string.IsNullOrEmpty(YooAssetSettingPath) == false) + { + if (Directory.Exists(YooAssetSettingPath)) + return YooAssetSettingPath; + } + + // 从Assets目录下搜索 + string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAssetSetting", SearchOption.AllDirectories); + if (allDirectorys.Length == 0) + { + YooAssetSettingPath = "Assets/YooAssetSetting"; + return YooAssetSettingPath; + } + + string targetDirectory = allDirectorys[0]; + if (allDirectorys.Length != 1) + { + Debug.LogError("Found multiple YooAssetSetting folder !"); + } + + YooAssetSettingPath = AbsolutePathToAssetPath(targetDirectory); + return YooAssetSettingPath; } /// diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs index 62a740d..711cd18 100644 --- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs @@ -26,13 +26,14 @@ namespace YooAsset.Editor private static void LoadSettingData() { // 加载配置文件 - _setting = AssetDatabase.LoadAssetAtPath(EditorDefine.ShaderVariantCollectorSettingFilePath); + string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(ShaderVariantCollectorSetting)}.asset"; + _setting = AssetDatabase.LoadAssetAtPath(settingFilePath); if (_setting == null) { - Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {EditorDefine.ShaderVariantCollectorSettingFilePath}"); + Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {settingFilePath}"); _setting = ScriptableObject.CreateInstance(); - EditorTools.CreateFileDirectory(EditorDefine.ShaderVariantCollectorSettingFilePath); - AssetDatabase.CreateAsset(Setting, EditorDefine.ShaderVariantCollectorSettingFilePath); + EditorTools.CreateFileDirectory(settingFilePath); + AssetDatabase.CreateAsset(Setting, settingFilePath); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }