提交 7572bbfb 编写于 作者: 魔术师Dix's avatar 魔术师Dix

完善脚本模板添加的功能;

上级 d244963e
%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:
fileFormatVersion: 2
guid: 78f67d703404d664fb1ea0ca4a7829c4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
*/ */
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
...@@ -76,49 +77,64 @@ namespace Lycianthes ...@@ -76,49 +77,64 @@ namespace Lycianthes
[Title("预设脚本配置"), HideLabel] [Title("预设脚本配置"), HideLabel]
public Dictionary<string, LycianthesScriptInfo> dictTemplate = new Dictionary<string, LycianthesScriptInfo>(); public Dictionary<string, LycianthesScriptInfo> dictTemplate = new Dictionary<string, LycianthesScriptInfo>();
/// <summary>
/// 其他脚本的配置
/// </summary>
[NonSerialized]
private List<LycianthesTemplateGroup> listOtherTemplate = new List<LycianthesTemplateGroup>();
public void ResetOtherTemplate() { listOtherTemplate?.Clear(); }
/// <summary> /// <summary>
/// 新建脚本 /// 新建脚本
/// </summary> /// </summary>
[Title("脚本创建"), Button("创建脚本", ButtonSizes.Medium)] [Title("脚本创建"), Button("创建脚本", ButtonSizes.Medium)]
public void CreateNewScript(string type) public void CreateNewScript(string type)
{ {
LycianthesScriptInfo temp; LycianthesScriptInfo temp = FindLycianthesScriptInfo(type);
if (dictTemplate.TryGetValue(type, out temp)) if (temp == null) return;
{
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);
}
//获取文件路径; public LycianthesScriptInfo FindLycianthesScriptInfo(string type)
string path = AssetDatabase.GetAssetPath(temp.Template); {
//创建脚本 LycianthesScriptInfo ret = null;
CreateScriptByTemplate.Version = Version; if (dictTemplate.TryGetValue(type, out ret)) return ret;
CreateScriptByTemplate.Author = AuthorName; foreach (var group in listOtherTemplate)
CreateScriptByTemplate.Company = Company; {
CreateScriptByTemplate.NameSpace = NameSpace; if (group.dictTemplate.TryGetValue(type, out ret))
//删除前面的/Asset return ret;
string curPath = temp.DefaultFolder.Substring(6);
CreateScriptByTemplate.CreateSript(path, curPath, temp.DefaultName);
} }
#if DEBUG_LYCIANTHES
Debug.LogError($"[Lycianthes] : 未找到对应脚本配置:{type}");
#endif
return null;
} }
public void CreateNewScript(string type, string curPath, string name) public void CreateNewScript(string type, string curPath, string name)
{ {
LycianthesScriptInfo temp; LycianthesScriptInfo temp = FindLycianthesScriptInfo(type);
if (dictTemplate.TryGetValue(type, out temp)) if (temp == null) return;
{
if (temp == null) //获取文件路径;
return; string path = AssetDatabase.GetAssetPath(temp.Template);
//创建脚本
//获取文件路径; CreateScriptByTemplate.Version = Version;
string path = AssetDatabase.GetAssetPath(temp.Template); CreateScriptByTemplate.Author = AuthorName;
//创建脚本 CreateScriptByTemplate.Company = Company;
CreateScriptByTemplate.Version = Version; CreateScriptByTemplate.NameSpace = NameSpace;
CreateScriptByTemplate.Author = AuthorName; //删除前面的/Asset
CreateScriptByTemplate.Company = Company; CreateScriptByTemplate.CreateScriptNoChosse(path, curPath, name);
CreateScriptByTemplate.NameSpace = NameSpace;
//删除前面的/Asset
CreateScriptByTemplate.CreateScriptNoChosse(path, curPath, name);
}
} }
/// <summary> /// <summary>
...@@ -127,24 +143,12 @@ namespace Lycianthes ...@@ -127,24 +143,12 @@ namespace Lycianthes
[Button("刷新")] [Button("刷新")]
public void Refresh() { AssetDatabase.Refresh(); } public void Refresh() { AssetDatabase.Refresh(); }
public void AddTemlateGroup(LycianthesTemplateGroup group) public void AddTemlateGroup(LycianthesTemplateGroup group)
{ {
if (group == null) return; if (group == null) return;
foreach (var item in group.dictTemplate) if (listOtherTemplate.Contains(group)) return;
{ listOtherTemplate.Add(group);
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);
}
} }
private List<string> tempKeyList = new List<string>(); private List<string> tempKeyList = new List<string>();
...@@ -153,6 +157,9 @@ namespace Lycianthes ...@@ -153,6 +157,9 @@ namespace Lycianthes
tempKeyList.Clear(); tempKeyList.Clear();
foreach (var item in dictTemplate) foreach (var item in dictTemplate)
tempKeyList.Add(item.Key); tempKeyList.Add(item.Key);
foreach (var item in listOtherTemplate)
foreach (var info in item.dictTemplate)
tempKeyList.Add(info.Key);
return tempKeyList; return tempKeyList;
} }
......
...@@ -45,6 +45,23 @@ namespace Lycianthes ...@@ -45,6 +45,23 @@ namespace Lycianthes
window.TargetPath = GetCurrentSelectFolderPath(); window.TargetPath = GetCurrentSelectFolderPath();
window.Version = PlayerSettings.bundleVersion; window.Version = PlayerSettings.bundleVersion;
window.CompanyName = PlayerSettings.companyName; 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<LycianthesTemplateGroup>(path);
group.OnEnable();
}
}
} }
/// <summary> /// <summary>
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
*/ */
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEditor;
using UnityEngine; using UnityEngine;
namespace Lycianthes namespace Lycianthes
...@@ -24,7 +24,7 @@ namespace Lycianthes ...@@ -24,7 +24,7 @@ namespace Lycianthes
[Title("预设脚本配置"), HideLabel] [Title("预设脚本配置"), HideLabel]
public Dictionary<string, LycianthesScriptInfo> dictTemplate = new Dictionary<string, LycianthesScriptInfo>(); public Dictionary<string, LycianthesScriptInfo> dictTemplate = new Dictionary<string, LycianthesScriptInfo>();
private void OnEnable() public void OnEnable()
{ {
LycianthesScriptCreator.Instance.AddTemlateGroup(this); LycianthesScriptCreator.Instance.AddTemlateGroup(this);
#if DEBUG_LYCIANTHES #if DEBUG_LYCIANTHES
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册