zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Editor/CalEditor/TeamplateTool.cs

72 lines
2.3 KiB
C#
Raw Normal View History

2021-04-08 20:09:59 +08:00
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using System.IO;
2021-05-01 11:27:41 +08:00
using UnityEditor;
2021-04-08 20:09:59 +08:00
using UnityEngine;
namespace Cal
{
[CreateAssetMenu]
public class TeamplateTool:Sirenix.OdinInspector.SerializedScriptableObject
{
public TextAsset templateTxt;
2021-05-01 11:27:41 +08:00
public TextAsset templateOpenUITxt;
public TextAsset templateUIEventTxt;
public TextAsset templateUIEventTypeTxt;
2021-04-08 20:09:59 +08:00
2021-05-01 11:27:41 +08:00
public string className;
public string uiRootName;
private string uiName=>uiRootName+"_"+className;
2021-04-08 20:09:59 +08:00
2021-05-01 11:27:41 +08:00
[FolderPath(AbsolutePath = false)]
2021-04-08 20:09:59 +08:00
public string pathRoot;
2021-05-01 11:27:41 +08:00
[FolderPath(AbsolutePath = false)]
public string pathEvent;
2021-04-08 20:09:59 +08:00
2021-05-01 11:27:41 +08:00
public void GenerateOpenUIEvent()
{
string str = templateOpenUITxt.text;
str = str.Replace("#className#", className);
str = str.Replace("#uiName#", uiName);
ET.Utility.FileOpation.CreateDirectory(Path.Combine(pathRoot, className));
string path = Path.Combine(pathRoot, className, $"Open{className}Event.cs");
ET.Utility.FileOpation.WriteString(path,str);
str = templateUIEventTypeTxt.text;
str = str.Replace("#className#", className);
str = str.Replace("#uiName#", uiName);
ET.Utility.FileOpation.CreateDirectory(Path.Combine(pathEvent));
path = Path.Combine(pathEvent, $"EventType.Open{className}.cs");
ET.Utility.FileOpation.WriteString(path,str);
AssetDatabase.Refresh();
}
2021-04-08 20:09:59 +08:00
[Button("生成UI")]
public void GenerateUI()
{
string str = templateTxt.text;
2021-05-01 11:27:41 +08:00
str = str.Replace("#className#", className);
str = str.Replace("#uiName#", uiName);
ET.Utility.FileOpation.CreateDirectory(Path.Combine(pathRoot, className));
string path = Path.Combine(pathRoot, className, $"{className}.cs");
ET.Utility.FileOpation.WriteString(path,str);
GenerateUIEvent();
GenerateOpenUIEvent();
AssetDatabase.Refresh();
2021-04-08 20:09:59 +08:00
}
public void GenerateUIEvent()
{
2021-05-01 11:27:41 +08:00
string str = templateUIEventTxt.text;
str = str.Replace("#className#", className);
str = str.Replace("#uiName#", uiName);
ET.Utility.FileOpation.CreateDirectory(Path.Combine(pathRoot, className));
string path = Path.Combine(pathRoot, className, $"{className}Event.cs");
ET.Utility.FileOpation.WriteString(path,str);
AssetDatabase.Refresh();
2021-04-08 20:09:59 +08:00
}
}
}