YooAssetSetting folder search location

YooAssetSetting文件夹全路径搜索定位
pull/9/head
hevinci 2022-04-28 23:29:15 +08:00
parent 62f1c050ca
commit 3de44a416c
14 changed files with 80 additions and 60 deletions

View File

@ -25,13 +25,14 @@ namespace YooAsset.Editor
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 // 加载配置文件
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(EditorDefine.AssetBundleBuilderSettingFilePath); string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleBuilderSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(settingFilePath);
if (_setting == null) if (_setting == null)
{ {
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {EditorDefine.AssetBundleBuilderSettingFilePath}"); Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>(); _setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleBuilderSettingFilePath); EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleBuilderSettingFilePath); AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
AssetDatabase.Refresh(); AssetDatabase.Refresh();
} }

View File

@ -37,7 +37,7 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleBuilder/{nameof(AssetBundleBuilderWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null) if (visualAsset == null)

View File

@ -50,7 +50,7 @@ namespace YooAsset.Editor
VisualElement root = rootVisualElement; VisualElement root = rootVisualElement;
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleDebugger/{nameof(AssetBundleDebuggerWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null) if (visualAsset == null)

View File

@ -24,7 +24,7 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(AssetListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); _visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)

View File

@ -24,7 +24,7 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleDebugger/VisualViewers/{nameof(BundleListDebuggerViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); _visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)

View File

@ -106,13 +106,14 @@ namespace YooAsset.Editor
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 // 加载配置文件
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleGrouperSetting>(EditorDefine.AssetBundleGrouperSettingFilePath); string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(AssetBundleGrouperSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleGrouperSetting>(settingFilePath);
if (_setting == null) if (_setting == null)
{ {
Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {EditorDefine.AssetBundleGrouperSettingFilePath}"); Debug.LogWarning($"Create new {nameof(AssetBundleGrouperSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleGrouperSetting>(); _setting = ScriptableObject.CreateInstance<AssetBundleGrouperSetting>();
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleGrouperSettingFilePath); EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleGrouperSettingFilePath); AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
AssetDatabase.Refresh(); AssetDatabase.Refresh();
} }

View File

@ -43,7 +43,7 @@ namespace YooAsset.Editor
_filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames(); _filterRuleList = AssetBundleGrouperSettingData.GetFilterRuleNames();
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleGrouper/{nameof(AssetBundleGrouperWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null) if (visualAsset == null)

View File

@ -51,7 +51,7 @@ namespace YooAsset.Editor
VisualElement root = this.rootVisualElement; VisualElement root = this.rootVisualElement;
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleReporter/{nameof(AssetBundleReporterWindow)}.uxml";
var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); var visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (visualAsset == null) if (visualAsset == null)

View File

@ -30,7 +30,7 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(AssetListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); _visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)

View File

@ -32,7 +32,7 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(BundleListReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); _visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)

View File

@ -37,7 +37,7 @@ namespace YooAsset.Editor
public void InitViewer() public void InitViewer()
{ {
// 加载布局文件 // 加载布局文件
string rootPath = EditorTools.GetYooAssetPath(); string rootPath = EditorTools.GetYooAssetSourcePath();
string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml"; string uxml = $"{rootPath}/Editor/AssetBundleReporter/VisualViewers/{nameof(SummaryReporterViewer)}.uxml";
_visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml); _visualAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(uxml);
if (_visualAsset == null) if (_visualAsset == null)

View File

@ -1,25 +1,9 @@
 using System;
using System;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class EditorDefine public class EditorDefine
{ {
/// <summary>
/// 资源包构建工具的配置文件存储路径
/// </summary>
public const string AssetBundleBuilderSettingFilePath = "Assets/YooAssetSetting/AssetBundleBuilderSetting.asset";
/// <summary>
/// 资源包分组工具的配置文件存储路径
/// </summary>
public const string AssetBundleGrouperSettingFilePath = "Assets/YooAssetSetting/AssetBundleGrouperSetting.asset";
/// <summary>
/// 着色器变种收集工具的配置文件存储路径
/// </summary>
public const string ShaderVariantCollectorSettingFilePath = "Assets/YooAssetSetting/ShaderVariantCollectorSetting.asset";
/// <summary> /// <summary>
/// 停靠窗口类型集合 /// 停靠窗口类型集合
/// </summary> /// </summary>
@ -55,16 +39,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public enum EAssetFileExtension public enum EAssetFileExtension
{ {
prefab, //预制体 prefab,
unity, //场景 unity,
fbx, //模型 fbx,
anim, //动画 anim,
controller, //控制器 controller,
png, //图片 png,
jpg, //图片 jpg,
mat, //材质球 mat,
shader, //着色器 shader,
ttf, //字体 ttf,
cs, //脚本 cs,
} }
} }

View File

@ -412,7 +412,8 @@ namespace YooAsset.Editor
#endregion #endregion
#region 路径 #region 路径
private static string YooAssetPath; private static string YooAssetSourcePath;
private static string YooAssetSettingPath;
/// <summary> /// <summary>
/// 获取规范的路径 /// 获取规范的路径
@ -423,27 +424,30 @@ namespace YooAsset.Editor
} }
/// <summary> /// <summary>
/// 获取资源框架目录路径 /// 获取资源框架源码路径
/// </summary> /// </summary>
public static string GetYooAssetPath() public static string GetYooAssetSourcePath()
{ {
if (string.IsNullOrEmpty(YooAssetPath) == false) if (string.IsNullOrEmpty(YooAssetSourcePath) == false)
return YooAssetPath; {
if (Directory.Exists(YooAssetSourcePath))
return YooAssetSourcePath;
}
// 从Pakcages目录下搜索 // 从Pakcages目录下搜索
string packagesPath = ("Packages/com.tuyoogame.yooasset/README.md"); string packagesPath = "Packages/com.tuyoogame.yooasset/README.md";
var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset)); var obj = AssetDatabase.LoadAssetAtPath(packagesPath, typeof(TextAsset));
if (obj != null) if (obj != null)
{ {
YooAssetPath = "Packages/com.tuyoogame.yooasset/"; YooAssetSourcePath = "Packages/com.tuyoogame.yooasset/";
return YooAssetPath; return YooAssetSourcePath;
} }
// 从Assets目录下搜索 // 从Assets目录下搜索
string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories); string[] allDirectorys = Directory.GetDirectories(Application.dataPath, "YooAsset", SearchOption.AllDirectories);
if (allDirectorys.Length == 0) if (allDirectorys.Length == 0)
{ {
Debug.LogError("Not found YooAsset Package !"); Debug.LogError("Not found YooAsset package !");
return string.Empty; return string.Empty;
} }
@ -463,8 +467,37 @@ namespace YooAsset.Editor
return string.Empty; return string.Empty;
} }
YooAssetPath = AbsolutePathToAssetPath(targetDirectory); YooAssetSourcePath = AbsolutePathToAssetPath(targetDirectory);
return YooAssetPath; return YooAssetSourcePath;
}
/// <summary>
/// 获取资源框架配置路径
/// </summary>
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;
} }
/// <summary> /// <summary>

View File

@ -26,13 +26,14 @@ namespace YooAsset.Editor
private static void LoadSettingData() private static void LoadSettingData()
{ {
// 加载配置文件 // 加载配置文件
_setting = AssetDatabase.LoadAssetAtPath<ShaderVariantCollectorSetting>(EditorDefine.ShaderVariantCollectorSettingFilePath); string settingFilePath = $"{EditorTools.GetYooAssetSettingPath()}/{nameof(ShaderVariantCollectorSetting)}.asset";
_setting = AssetDatabase.LoadAssetAtPath<ShaderVariantCollectorSetting>(settingFilePath);
if (_setting == null) if (_setting == null)
{ {
Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {EditorDefine.ShaderVariantCollectorSettingFilePath}"); Debug.LogWarning($"Create new {nameof(ShaderVariantCollectorSetting)}.asset : {settingFilePath}");
_setting = ScriptableObject.CreateInstance<ShaderVariantCollectorSetting>(); _setting = ScriptableObject.CreateInstance<ShaderVariantCollectorSetting>();
EditorTools.CreateFileDirectory(EditorDefine.ShaderVariantCollectorSettingFilePath); EditorTools.CreateFileDirectory(settingFilePath);
AssetDatabase.CreateAsset(Setting, EditorDefine.ShaderVariantCollectorSettingFilePath); AssetDatabase.CreateAsset(Setting, settingFilePath);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
AssetDatabase.Refresh(); AssetDatabase.Refresh();
} }