public class CreatStateTypeScripts
{
public static void CreatScripts()
{
foreach (StateType item in System.Enum.GetValues(typeof(StateType)))
{
string savePath = "/Scripts/AnimatorScripts/States/";
string classname = item.ToString();
StringBuilder sb = new StringBuilder();
sb.Append("/*------------------------------------------------------------\n");
sb.Append("--------------------Generate By Utilities.--------------------\n");
sb.Append("------------------------------------------------------------*/\n");
sb.Append("public class ").Append(classname).Append(" : ").Append("StateBase").Append("\n");
sb.Append("{\n");
sb.Append(" public override void OnEnter()");
sb.Append("\n");
sb.Append(" {\n");
sb.Append(" m_Aniamtor.SetBool(\"");
sb.Append(classname);
sb.Append("\", true);");
sb.Append("\n");
sb.Append(" }\n");
sb.Append(" public override void OnExit()");
sb.Append("\n");
sb.Append(" {\n");
sb.Append(" m_Aniamtor.SetBool(\"");
sb.Append(classname);
sb.Append("\", false);");
sb.Append("\n");
sb.Append(" }\n");
sb.Append(" public override void OnUpdate()");
sb.Append("\n");
sb.Append(" {\n");
sb.Append(" base.OnUpdate();");
sb.Append("\n");
sb.Append(" }\n");
sb.Append("}");
string dirPath = Application.dataPath + savePath;
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
string path = dirPath + classname + ".cs";
File.Open(path, FileMode.OpenOrCreate).Dispose();
File.WriteAllText(path, sb.ToString(), Encoding.UTF8);
Debug.Log(string.Format("输出文件:{0}.cs", classname));
}
AssetDatabase.Refresh();
}
}
void OnGUI()
{
EditorGUILayout.Space();
GUI.color = Color.yellow;
if (GUILayout.Button("生成StateType脚本"))
{
CreatStateTypeScripts.CreatScripts();
}
}