public void GenerateClass(NodeInfo nodeInfo) { //Checking if object is not null Assert.IsNotNull(nodeInfo); string directoryPath = Environment.CurrentDirectory + "/Assets"; using (StreamWriter sw = new StreamWriter(Path.Combine(directoryPath, nodeInfo.ClassName + ".cs"))) { //adding library's sw.WriteLine("using UnityEngine;"); sw.WriteLine("using System.Collections;"); sw.WriteLine("using System.Collections.Generic;"); sw.WriteLine(""); //white space sw.WriteLine("/// <Information>"); sw.WriteLine("/// This class is generated with the UML tool from Geoffrey Hendrikx."); sw.WriteLine("/// </Information>"); if (nodeInfo.Parent != string.Empty) { sw.WriteLine(nodeInfo.ClassAccessModifiers.ToString().ToLower() + " class " + nodeInfo.ClassName + " : " + nodeInfo.Parent); } else { sw.WriteLine(nodeInfo.ClassAccessModifiers.ToString().ToLower() + " class " + nodeInfo.ClassName); } sw.WriteLine("{"); //adding variables for (int i = 0; i < nodeInfo.VariableInfo.Count; i++) { ClassContent variable = nodeInfo.VariableInfo[i]; sw.WriteLine("\t" + variable.AccessModifiers.ToString().ToLower() + " " + variable.Type + " " + variable.Name + ";"); } sw.WriteLine(" "); // whitespace for (int i = 0; i < nodeInfo.MethodeInfo.Count; i++) { ClassContent methode = nodeInfo.MethodeInfo[i]; if (methode.Name.EndsWith(")")) { sw.WriteLine("\t" + methode.AccessModifiers.ToString().ToLower() + " " + methode.Type + " " + methode.Name + "{ }"); } else { sw.WriteLine("\t" + methode.AccessModifiers.ToString().ToLower() + " " + methode.Type + " " + methode.Name + "() { }"); } } sw.WriteLine("}"); sw.Flush(); sw.Close(); } AssetDatabase.Refresh(); }
/// <summary> /// Drawing the node /// </summary> public void Draw() { GUILayout.BeginVertical(); GUILayout.Label("Class name"); GUILayout.BeginHorizontal(); ClassAccessModifiers = (AccessModifiers)EditorGUILayout.EnumPopup((AccessModifiers)ClassAccessModifiers, GUILayout.MaxWidth(70)); ClassName = GUILayout.TextField(ClassName); GUILayout.EndHorizontal(); GUILayout.Label("Inheritance"); Parent = GUILayout.TextField(Parent); GUILayout.Space(15); //variables GUILayout.Label("Variables \t Type \t Name"); //Variable for (int i = 0; i < variableInfo.Count; i++) { ClassContent variable = VariableInfo[i]; GUILayout.BeginHorizontal(); //AccessModifier Type Variable variable.AccessModifiers = (AccessModifiers)EditorGUILayout.EnumPopup((AccessModifiers)variable.AccessModifiers, GUILayout.MaxWidth(70)); variable.Type = GUILayout.TextField(variable.Type); variable.Name = GUILayout.TextField(variable.Name); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (variableInfo.Count == 1) { VariableInfo = new List <ClassContent>(); } VariableInfo.Remove(variableInfo[i]); } GUILayout.EndHorizontal(); } //adding variable to the list. if (GUILayout.Button("Add variable", GUILayout.MaxWidth(100))) { variableInfo.Add(new ClassContent()); } GUILayout.Space(15); //Methodes GUILayout.Label("Methods \t Type \t Name"); for (int i = 0; i < methodeInfo.Count; i++) { ClassContent methode = methodeInfo[i]; GUILayout.BeginHorizontal(); //AccessModifier Type Methode methode.AccessModifiers = (AccessModifiers)EditorGUILayout.EnumPopup((AccessModifiers)methode.AccessModifiers, GUILayout.MaxWidth(70)); methode.Type = GUILayout.TextField(methode.Type); methode.Name = GUILayout.TextField(methode.Name); //methode.SetStructVariables(accesModifierTemp, typeTemp, nameTemp); if (GUILayout.Button("X", GUILayout.MaxWidth(20))) { if (methodeInfo.Count == 1) { methodeInfo = new List <ClassContent>(); } methodeInfo.RemoveAt(i); } GUILayout.EndHorizontal(); } //adding methode to the list. if (GUILayout.Button("Add methods", GUILayout.MaxWidth(100))) { methodeInfo.Add(new ClassContent()); } GUILayout.Space(15); GUILayout.EndVertical(); }