Skip to content

Commit f7c6c69

Browse files
Added option to generate empty class
1 parent 699f0ee commit f7c6c69

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

Editor/GenerateFileEditorWindow.cs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ namespace ElRaccoone.EntityComponentSystem.Editor {
99
public enum GenerateFileType {
1010
Controller,
1111
ComponentAndSystem,
12-
Service
12+
Service,
13+
Class
1314
}
1415

1516
public class GenerateFileEditorWindow : EditorWindow {
@@ -37,6 +38,12 @@ private static void GenerateNewService () {
3738
EditorWindow.GetWindowWithRect (typeof (GenerateFileEditorWindow), new Rect (0, 0, 400, 180), true, "Generate Service");
3839
}
3940

41+
[MenuItem ("ECS/Generate Class", false, 100)]
42+
private static void GenerateNewClass () {
43+
GenerateFileEditorWindow.generateFileType = GenerateFileType.Class;
44+
EditorWindow.GetWindowWithRect (typeof (GenerateFileEditorWindow), new Rect (0, 0, 400, 180), true, "Generate Class");
45+
}
46+
4047
private void OnGUI () {
4148
var _newFileTypeReadable = "";
4249
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Controller)
@@ -45,6 +52,8 @@ private void OnGUI () {
4552
_newFileTypeReadable = "Component and System";
4653
else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Service)
4754
_newFileTypeReadable = "Service";
55+
else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Class)
56+
_newFileTypeReadable = "Class";
4857
GUILayout.BeginHorizontal ();
4958
GUILayout.Space (20);
5059
GUILayout.BeginVertical ();
@@ -62,9 +71,12 @@ private void OnGUI () {
6271
} else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.ComponentAndSystem) {
6372
if (GUILayout.Button ("Generate " + this.fileName + "Component and -System"))
6473
this.Generate ();
65-
} else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Service)
74+
} else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Service) {
6675
if (GUILayout.Button ("Generate " + this.fileName + "Service"))
6776
this.Generate ();
77+
} else if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Class)
78+
if (GUILayout.Button ("Generate " + this.fileName))
79+
this.Generate ();
6880
GUILayout.Space (20);
6981
GUILayout.EndVertical ();
7082
GUILayout.Space (20);
@@ -80,8 +92,8 @@ private void Generate () {
8092

8193
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Controller)
8294
this.WriteContentToFile (this.FindDirectoryWithName (Application.dataPath, "Controllers"), _fileName + "Controller", "cs", new string[] {
83-
_importCommonNamespaces ? "using UnityEngine;" : null,
8495
"using ElRaccoone.EntityComponentSystem;",
96+
_importCommonNamespaces ? "using UnityEngine;" : null,
8597
_importCommonNamespaces ? "using System.Collections.Generic;" : null,
8698
"",
8799
_addFileHeaderComments ? "/*" : null,
@@ -101,9 +113,9 @@ private void Generate () {
101113

102114
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.ComponentAndSystem)
103115
this.WriteContentToFile (this.FindDirectoryWithName (Application.dataPath, "Components"), _fileName + "Component", "cs", new string[] {
104-
_importCommonNamespaces? "using UnityEngine;" : null,
105116
"using ElRaccoone.EntityComponentSystem;",
106-
_importCommonNamespaces? "using System.Collections.Generic;" : null,
117+
_importCommonNamespaces ? "using UnityEngine;" : null,
118+
_importCommonNamespaces ? "using System.Collections.Generic;" : null,
107119
"",
108120
_addFileHeaderComments ? "/*" : null,
109121
_addFileHeaderComments ? " * Project: " + PlayerSettings.productName : null,
@@ -117,9 +129,9 @@ private void Generate () {
117129

118130
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.ComponentAndSystem)
119131
this.WriteContentToFile (this.FindDirectoryWithName (Application.dataPath, "Systems"), _fileName + "System", "cs", new string[] {
120-
_importCommonNamespaces? "using UnityEngine;" : null,
121132
"using ElRaccoone.EntityComponentSystem;",
122-
_importCommonNamespaces? "using System.Collections.Generic;" : null,
133+
_importCommonNamespaces ? "using UnityEngine;" : null,
134+
_importCommonNamespaces ? "using System.Collections.Generic;" : null,
123135
"",
124136
_addFileHeaderComments ? "/*" : null,
125137
_addFileHeaderComments ? " * Project: " + PlayerSettings.productName : null,
@@ -146,9 +158,9 @@ private void Generate () {
146158

147159
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Service)
148160
this.WriteContentToFile (this.FindDirectoryWithName (Application.dataPath, "Services"), _fileName + "Service", "cs", new string[] {
149-
_importCommonNamespaces? "using UnityEngine;" : null,
150161
"using ElRaccoone.EntityComponentSystem;",
151-
_importCommonNamespaces? "using System.Collections.Generic;" : null,
162+
_importCommonNamespaces ? "using UnityEngine;" : null,
163+
_importCommonNamespaces ? "using System.Collections.Generic;" : null,
152164
"",
153165
_addFileHeaderComments ? "/*" : null,
154166
_addFileHeaderComments ? " * Project: " + PlayerSettings.productName : null,
@@ -164,6 +176,21 @@ private void Generate () {
164176
"}"
165177
});
166178

179+
if (GenerateFileEditorWindow.generateFileType == GenerateFileType.Class)
180+
this.WriteContentToFile (Application.dataPath, _fileName + "", "cs", new string[] {
181+
_importCommonNamespaces ? "using UnityEngine;" : null,
182+
_importCommonNamespaces ? "using System.Collections.Generic;" : null,
183+
_importCommonNamespaces ? "" : null,
184+
_addFileHeaderComments ? "/*" : null,
185+
_addFileHeaderComments ? " * Project: " + PlayerSettings.productName : null,
186+
_addFileHeaderComments ? " * Author: " : null,
187+
_addFileHeaderComments ? " *" : null,
188+
_addFileHeaderComments ? " * " + _fileName + "." : null,
189+
_addFileHeaderComments ? " */" : null,
190+
"public class " + _fileName + " {",
191+
"}"
192+
});
193+
167194
this.Close ();
168195
}
169196

0 commit comments

Comments
 (0)