/// <summary> /// Creates a new C# script /// </summary> /// <param name="templateName"></param> public static void CreateScript(string templateName) { var path = Path.Combine(EcsCore.GetCurrentFolderPath(), "Untitled.txt"); var endAction = CreateInstance <CreateScriptEndAction>(); var config = EcsConfig.GetActiveConfig(); var template = GetScriptTemplate(templateName); endAction.LoadDependencies(config, template); ProjectWindowUtil.StartNameEditingIfProjectWindowExists( 0, endAction, path, EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D, null); }
private void OnGUI() { GUILayout.Label("Select a template", EditorStyles.boldLabel); EditorGUILayout.BeginScrollView(new Vector2(0, 0)); var files = Directory.GetFiles(Path.Combine(EcsCore.GetPluginRootFolderPath(), "Templates")) .Where(f => f.EndsWith(".asset")); // skip .meta files foreach (var file in files) { var filename = Path.GetFileNameWithoutExtension(file); GUILayout.BeginHorizontal(); if (GUILayout.Button(filename)) { if (_window != null) { _window.Close(); _window = null; } EcsScriptTemplate.CreateScript(filename); } if (GUILayout.Button("X", GUILayout.Width(20))) { if (EditorUtility.DisplayDialog("Delete warning", "Delete " + filename + " template?", "Yes", "No")) { AssetDatabase.DeleteAsset(file); } } GUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); if (GUILayout.Button("(+) New Template")) { EcsScriptTemplate.CreateNewDefaultTemplate(); } GUILayout.EndHorizontal(); }
/// <summary> /// Gets file path to Config.asset file. Path is returned even if file doesn't exist. /// </summary> /// <returns>Config.asset file path</returns> public static string GetConfigPath() { return(Path.Combine(EcsCore.GetPluginRootFolderPath(), ConfigFileName)); }
/// <summary> /// Gets a specific template instance /// </summary> /// <param name="name"></param> /// <returns></returns> public static EcsScriptTemplate GetScriptTemplate(string name) { return(AssetDatabase.LoadAssetAtPath(Path.Combine(EcsCore.GetPluginRootFolderPath(), "Templates/" + name + ".asset"), typeof(EcsScriptTemplate)) as EcsScriptTemplate); }
/// <summary> /// Path to templates folder /// </summary> /// <returns></returns> public static string GetTemplateFolderPath() { return(Path.Combine(EcsCore.GetPluginRootFolderPath(), "Templates")); }