private static void AddSourceProcess(GenerateStateInfo stateInfo) { stateInfo.className = stateInfo.className.Substring(0, 1).ToUpper() + stateInfo.className.Substring(1, stateInfo.className.Length - 1); if (stateInfo.className.Length > 5) { if (stateInfo.className.Substring(stateInfo.className.Length - 5, 5) != "State") { stateInfo.className += "State"; } } else { stateInfo.className += "State"; } string statesFolderPath = Path.GetFullPath( AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("StateBase")[0])).Split(new string[] { "Scripts" }, StringSplitOptions.None)[0] + "Scripts/States"; string sourcePath = Path.Combine(statesFolderPath, stateInfo.className + ".cs"); using (FileStream fs = File.Create(sourcePath)) { using (StreamWriter sw = new StreamWriter(fs)) { string tmplatePath = Path.GetFullPath(AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets(templates[stateInfo.baseClass])[0])); string src = File.ReadAllText(tmplatePath).Replace("{className}", stateInfo.className); sw.Write(src); } } Debug.LogWarning("generated: " + sourcePath); AssetDatabase.Refresh(ImportAssetOptions.ImportRecursive); window.Close(); }
public static void WindowOpen() { stateInfo = new GenerateStateInfo(); window = EditorWindow.GetWindow <StateGenerator>("StateGenerator"); }