Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
executable file
·183 lines (147 loc) · 5.26 KB
/
Copy pathProgram.cs
File metadata and controls
executable file
·183 lines (147 loc) · 5.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
using System.IO;
class Program
{
public static string actorName = "";
public static List<string> componentNames = new List<string>();
public static string componentPrefix = "has";
public static bool generateSystem = true;
public static bool generateUpdateMethods = true;
public static bool generateFixedUpdateMethods = true;
public static bool generateLateUpdateMethods = true;
public static bool forceOverwrite = false;
public static bool componentMode = true;
#if OS_WINDOWS
public const string sl = "\\";
#else
public const string sl = "/";
#endif
public const string ASSETS_FOLDER = "Assets";
public const string UP_ASSETS_FOLDER = $"..{sl}Assets";
public static string assetsPath = "";
public static string entitiesFolder = "";
static void Main(string[] args)
{
if (args.Length == 0)
{
Debug.LogError("CAS requires parameters");
return;
}
else
{
if (Directory.Exists(ASSETS_FOLDER))
assetsPath = ASSETS_FOLDER;
else if (Directory.Exists(UP_ASSETS_FOLDER))
assetsPath = UP_ASSETS_FOLDER;
else
{
Debug.LogError("Could not find the Assets folder");
return;
}
entitiesFolder = $"{assetsPath}{sl}Scripts{sl}Entities";
actorName = args[0];
actorName = actorName.FirstCharToUpper();
// Components
if (args.Length > 1)
{
for (int i = 1; i < args.Length; i++)
{
string arg = args[i];
// Flag
if (arg[0] == '-')
{
componentMode = false;
switch (arg)
{
case "-p":
case "--prefix":
if (i < args.Length - 1)
{
var potentialPrefix = args[i+1];
if (potentialPrefix[0] != '-')
componentPrefix = potentialPrefix;
}
break;
case "-f":
case "--force":
forceOverwrite = true;
break;
case "--no-system":
generateSystem = false;
break;
case "--no-update":
generateUpdateMethods = false;
break;
case "--no-lateupdate":
generateLateUpdateMethods = false;
break;
case "--no-fixedupdate":
generateFixedUpdateMethods = false;
break;
}
}
else if (componentMode)
{
componentNames.Add(arg.FirstCharToUpper());
}
}
}
Debug.Log($"Generating {actorName} actor...");
GenerateActorClasses();
if (componentNames.Count > 0)
{
if (componentNames.Count > 1)
Debug.Log("Generating components...");
foreach (var componentName in componentNames)
GenerateComponentClasses(componentName);
}
Debug.Log("");
}
}
public static void GenerateComponentClasses(string componentName)
{
Debug.Log($"Generating {componentName}...");
string folderPath = $"{entitiesFolder}{sl}{actorName}{sl}Components{sl}{componentName}";
string editorFolderPath = $"{folderPath}{sl}Editor";
string configClassPath = $"{folderPath}{sl}{actorName}{componentName}Config.cs";
string systemClassPath = $"{folderPath}{sl}{actorName}{componentName}System.cs";
string extensionClassPath = $"{folderPath}{sl}{actorName}{componentName}Ext.cs";
string editorClassPath = $"{editorFolderPath}{sl}{actorName}{componentName}ConfigEditor.cs";
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
if (!Directory.Exists(editorFolderPath))
Directory.CreateDirectory(editorFolderPath);
Generator.CreateConfigClass(configClassPath, actorName, componentName);
Generator.CreateComponentConfigEditorClass(editorClassPath, actorName, componentName);
if (generateSystem)
Generator.CreateSystemClass(systemClassPath, actorName, componentName);
Generator.CreateExtensionClass(extensionClassPath, actorName, componentPrefix, componentName);
Debug.Log("Done!\n");
}
public static void GenerateActorClasses()
{
string actorFolderPath = $"{entitiesFolder}{sl}{actorName}";
string componentsFolderPath = $"{actorFolderPath}{sl}Components";
string editorFolderPath = $"{actorFolderPath}{sl}Editor";
string actorBase = $"{actorFolderPath}{sl}{actorName}";
string mainClassPath = $"{actorBase}.cs";
string baseComponentConfigPath = $"{actorBase}ComponentConfig.cs";
string actorConfigClassPath = $"{actorBase}Config.cs";
string managerClassPath = $"{actorBase}ActorManager.cs";
string factoryClassPath = $"{actorBase}Factory.cs";
string baseSystemClassPath = $"{actorBase}System.cs";
string actorConfigEditorClassPath = $"{editorFolderPath}{sl}{actorName}ConfigEditor.cs";
if (!Directory.Exists(componentsFolderPath))
Directory.CreateDirectory(componentsFolderPath);
if (!Directory.Exists(editorFolderPath))
Directory.CreateDirectory(editorFolderPath);
Generator.CreateMainActorClass(mainClassPath, actorName, generateUpdateMethods, generateFixedUpdateMethods, generateLateUpdateMethods);
Generator.CreateComponentConfigClass(baseComponentConfigPath, actorName);
Generator.CreateActorConfigClass(actorConfigClassPath, actorName);
Generator.CreateActorManagerClass(managerClassPath, actorName);
Generator.CreateActorFactoryClass(factoryClassPath, actorName);
Generator.CreateSystemBaseClass(baseSystemClassPath, actorName, generateUpdateMethods, generateFixedUpdateMethods, generateLateUpdateMethods);
Generator.CreateActorConfigEditorClass(actorConfigEditorClassPath, actorName);
Debug.Log("Done!\n");
}
}