using UnityEngine;
namespace Feif.UIFramework.Editor
{
[CreateAssetMenu(fileName = "UIFrameSetting", menuName = "UIFrame/UIFrameSetting", order = 0)]
public class UIFrameSetting : ScriptableObject
{
public TextAsset UIBaseTemplate;
public TextAsset UIComponentTemplate;
public TextAsset UIPanelTemplate;
public TextAsset UIWindowTemplate;
public bool AutoReference = true;
#if UNITY_EDITOR
private void Reset()
{
var ms = UnityEditor.MonoScript.FromScriptableObject(this);
var path = UnityEditor.AssetDatabase.GetAssetPath(ms);
Debug.Log($"{nameof(UIFrameSetting)}: path = {path}");
var resPath = System.IO.Path.GetDirectoryName(path).Replace("Scripts", "Resources");
var fields = GetType().GetFields();
foreach (var field in fields)
{
if (field.Name.EndsWith("Template"))
{
var file = System.IO.Path.Combine(resPath, $"{field.Name}.txt");
var res = UnityEditor.AssetDatabase.LoadAssetAtPath<TextAsset>(file);
field.SetValue(this, res);
}
}
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
}
效果如下:
代码如下: