feifeid47 / Unity-Async-UIFrame

简单易用的Unity异步UI框架。 足够轻量,无第三方依赖。 兼容多种资源管理系统(Addressable、YooAssets等)。支持使用HybridCLR热更新。 支持自动引用。 支持对UI面板的销毁控制,使内存优化更方便。 支持子UI,子子UI,子子子UI......
Apache License 2.0
274 stars 35 forks source link

加个功能:在创建 UIFrameSettings 时自动捕获代码模板。 #1

Closed Bian-Sh closed 1 year ago

Bian-Sh commented 1 year ago

效果如下: autosigned

代码如下:

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
    }
}
feifeid47 commented 1 year ago

谢谢反馈,后续更新会加上😊