diff --git a/Asset/LycianthesTemplateGroup.asset b/Asset/LycianthesTemplateGroup.asset deleted file mode 100644 index cda2e0af07f17cb5d4fadd6f65d2b5c287e4a9ff..0000000000000000000000000000000000000000 --- a/Asset/LycianthesTemplateGroup.asset +++ /dev/null @@ -1,14 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 27752d2b796118843a746b67b337476c, type: 3} - m_Name: LycianthesTemplateGroup - m_EditorClassIdentifier: diff --git a/Asset/LycianthesTemplateGroup.asset.meta b/Asset/LycianthesTemplateGroup.asset.meta deleted file mode 100644 index 36e77a54ac8b64479ab3e416e06af502c77b074e..0000000000000000000000000000000000000000 --- a/Asset/LycianthesTemplateGroup.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 78f67d703404d664fb1ea0ca4a7829c4 -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/LycianthesScriptCreator.cs b/Editor/LycianthesScriptCreator.cs index d56ec53e13b235034f919ba6f02337b2934c5f6a..a5d97915186588dde3105f264b83f04071ff5ed1 100644 --- a/Editor/LycianthesScriptCreator.cs +++ b/Editor/LycianthesScriptCreator.cs @@ -8,6 +8,7 @@ */ using Sirenix.OdinInspector; +using System; using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -76,49 +77,64 @@ namespace Lycianthes [Title("预设脚本配置"), HideLabel] public Dictionary dictTemplate = new Dictionary(); + /// + /// 其他脚本的配置 + /// + [NonSerialized] + private List listOtherTemplate = new List(); + + public void ResetOtherTemplate() { listOtherTemplate?.Clear(); } + /// /// 新建脚本 /// [Title("脚本创建"), Button("创建脚本", ButtonSizes.Medium)] public void CreateNewScript(string type) { - LycianthesScriptInfo temp; - if (dictTemplate.TryGetValue(type, out temp)) - { - if (temp == null) - return; + LycianthesScriptInfo temp = FindLycianthesScriptInfo(type); + if (temp == null) return; + + //获取文件路径; + string path = AssetDatabase.GetAssetPath(temp.Template); + //创建脚本 + CreateScriptByTemplate.Version = Version; + CreateScriptByTemplate.Author = AuthorName; + CreateScriptByTemplate.Company = Company; + CreateScriptByTemplate.NameSpace = NameSpace; + //删除前面的/Asset + string curPath = temp.DefaultFolder.Substring(6); + CreateScriptByTemplate.CreateSript(path, curPath, temp.DefaultName); + } - //获取文件路径; - string path = AssetDatabase.GetAssetPath(temp.Template); - //创建脚本 - CreateScriptByTemplate.Version = Version; - CreateScriptByTemplate.Author = AuthorName; - CreateScriptByTemplate.Company = Company; - CreateScriptByTemplate.NameSpace = NameSpace; - //删除前面的/Asset - string curPath = temp.DefaultFolder.Substring(6); - CreateScriptByTemplate.CreateSript(path, curPath, temp.DefaultName); + public LycianthesScriptInfo FindLycianthesScriptInfo(string type) + { + LycianthesScriptInfo ret = null; + if (dictTemplate.TryGetValue(type, out ret)) return ret; + foreach (var group in listOtherTemplate) + { + if (group.dictTemplate.TryGetValue(type, out ret)) + return ret; } +#if DEBUG_LYCIANTHES + Debug.LogError($"[Lycianthes] : 未找到对应脚本配置:{type}"); +#endif + return null; } public void CreateNewScript(string type, string curPath, string name) { - LycianthesScriptInfo temp; - if (dictTemplate.TryGetValue(type, out temp)) - { - if (temp == null) - return; - - //获取文件路径; - string path = AssetDatabase.GetAssetPath(temp.Template); - //创建脚本 - CreateScriptByTemplate.Version = Version; - CreateScriptByTemplate.Author = AuthorName; - CreateScriptByTemplate.Company = Company; - CreateScriptByTemplate.NameSpace = NameSpace; - //删除前面的/Asset - CreateScriptByTemplate.CreateScriptNoChosse(path, curPath, name); - } + LycianthesScriptInfo temp = FindLycianthesScriptInfo(type); + if (temp == null) return; + + //获取文件路径; + string path = AssetDatabase.GetAssetPath(temp.Template); + //创建脚本 + CreateScriptByTemplate.Version = Version; + CreateScriptByTemplate.Author = AuthorName; + CreateScriptByTemplate.Company = Company; + CreateScriptByTemplate.NameSpace = NameSpace; + //删除前面的/Asset + CreateScriptByTemplate.CreateScriptNoChosse(path, curPath, name); } /// @@ -127,24 +143,12 @@ namespace Lycianthes [Button("刷新")] public void Refresh() { AssetDatabase.Refresh(); } - public void AddTemlateGroup(LycianthesTemplateGroup group) { if (group == null) return; - foreach (var item in group.dictTemplate) - { - var k = item.Key; - var v = item.Value; - if (dictTemplate.ContainsKey(k)) - { -#if DEBUG_LYCIANTHES - Debug.LogError($"[Lycianthes]: 已存在Key : {k}"); -#endif - continue; - } - dictTemplate.Add(k, v); - } + if (listOtherTemplate.Contains(group)) return; + listOtherTemplate.Add(group); } private List tempKeyList = new List(); @@ -153,6 +157,9 @@ namespace Lycianthes tempKeyList.Clear(); foreach (var item in dictTemplate) tempKeyList.Add(item.Key); + foreach (var item in listOtherTemplate) + foreach (var info in item.dictTemplate) + tempKeyList.Add(info.Key); return tempKeyList; } diff --git a/Editor/LycianthesScriptWindow.cs b/Editor/LycianthesScriptWindow.cs index 64de4ebe4dc9dc02870a5ad8825e9036aa30eaff..9bf4a2cd4b523ebb43747aa2c63902f5cf9bb48e 100644 --- a/Editor/LycianthesScriptWindow.cs +++ b/Editor/LycianthesScriptWindow.cs @@ -45,6 +45,23 @@ namespace Lycianthes window.TargetPath = GetCurrentSelectFolderPath(); window.Version = PlayerSettings.bundleVersion; window.CompanyName = PlayerSettings.companyName; + window.creator.ResetOtherTemplate(); + AutoLoadTemplateGroup(); + } + + private static void AutoLoadTemplateGroup() + { + + var guids = AssetDatabase.FindAssets("t:LycianthesTemplateGroup"); + foreach (var guid in guids) + { + var path = AssetDatabase.GUIDToAssetPath(guid); + if (path.EndsWith(".asset")) + { + var group = AssetDatabase.LoadAssetAtPath(path); + group.OnEnable(); + } + } } /// diff --git a/Editor/LycianthesTemplateGroup.cs b/Editor/LycianthesTemplateGroup.cs index 29bf33d53656cff26fdc8344dd0621d3b374f039..10a3e6ffaa40c7e6185927ae94b01518f2e555d2 100644 --- a/Editor/LycianthesTemplateGroup.cs +++ b/Editor/LycianthesTemplateGroup.cs @@ -8,8 +8,8 @@ */ using Sirenix.OdinInspector; +using System; using System.Collections.Generic; -using UnityEditor; using UnityEngine; namespace Lycianthes @@ -24,7 +24,7 @@ namespace Lycianthes [Title("预设脚本配置"), HideLabel] public Dictionary dictTemplate = new Dictionary(); - private void OnEnable() + public void OnEnable() { LycianthesScriptCreator.Instance.AddTemlateGroup(this); #if DEBUG_LYCIANTHES