提交 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 @@
*/
using Sirenix.OdinInspector;
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
......@@ -76,49 +77,64 @@ namespace Lycianthes
[Title("预设脚本配置"), HideLabel]
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>
[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);
}
/// <summary>
......@@ -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<string> tempKeyList = new List<string>();
......@@ -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;
}
......
......@@ -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<LycianthesTemplateGroup>(path);
group.OnEnable();
}
}
}
/// <summary>
......
......@@ -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<string, LycianthesScriptInfo> dictTemplate = new Dictionary<string, LycianthesScriptInfo>();
private void OnEnable()
public void OnEnable()
{
LycianthesScriptCreator.Instance.AddTemlateGroup(this);
#if DEBUG_LYCIANTHES
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册