Skip to content

Commit c81d356

Browse files
authored
Merge pull request #2 from danigfedev/Generic_Events_With_Interfaces_Refactor
Generic events with interfaces refactor
2 parents 79366d9 + d4424c9 commit c81d356

File tree

110 files changed

+1780
-538
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+1780
-538
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
README.md.meta
1+
#These override the global git settings (we exclude all files ended with ~, typically used by backup files)
2+
!Samples~/
3+
!Documentation~/
4+
!Tests~/

CustomScriptTemplates/GenericSOEventListenerTemplate.txt

Lines changed: 0 additions & 28 deletions
This file was deleted.

CustomScriptTemplates/GenericSOEventTemplate.txt

Lines changed: 0 additions & 40 deletions
This file was deleted.

CustomScriptTemplates/NoArgsSOEventListenerTemplate.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

CustomScriptTemplates/NoArgsSOEventTemplate.txt

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using SOBaseEvents;
2+
<CUSTOM_NAMESPACE_LIST>
3+
<NAMESPACE_DECLARATION_START>
4+
public class <SCRIPT_NAME> : EventListener<<SO_EVENT_NAME><ARGUMENT_TYPE_LIST>>
5+
{
6+
7+
}
8+
<NAMESPACE_DECLARATION_END>

CustomScriptTemplates/NoArgsSOEventListenerTemplate.txt.meta renamed to CustomScriptTemplates/SOEventListenerTemplate.txt.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using SOBaseEvents;
2+
using UnityEngine;
3+
<CUSTOM_NAMESPACE_LIST>
4+
<NAMESPACE_DECLARATION_START>
5+
[CreateAssetMenu(fileName ="<SO_FILE_NAME>", menuName ="EspidiGames/SO Events/<SO_MENU_NAME>", order = 20)]
6+
public class <SCRIPT_NAME> : EventSOBase<ARGUMENT_TYPE_LIST>
7+
{
8+
9+
}
10+
<NAMESPACE_DECLARATION_END>

CustomScriptTemplates/GenericSOEventListenerTemplate.txt.meta renamed to CustomScriptTemplates/SOEventTemplate.txt.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/AssetCreationMenu.cs

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ public class AssetCreationMenu : UnityEditor.Editor
1818
private const string EventIconRelativepath = "/Icons/event.png";
1919
private const string EventListenerIconRelativePath = "/Icons/listener.png";
2020

21-
private const string GenericSOEventTemplatePath = "/CustomScriptTemplates/GenericSOEventTemplate.txt";
22-
private const string NoArgsSOEventTemplatePath = "/CustomScriptTemplates/NoArgsSOEventTemplate.txt";
23-
24-
private const string GenericSOEventListenerTemplatePath = "/CustomScriptTemplates/GenericSOEventListenerTemplate.txt";
25-
private const string NoArgsSOEventListenerTemplatePath = "/CustomScriptTemplates/NoArgsSOEventListenerTemplate.txt";
21+
private const string GenericSOEventTemplatePath = "/CustomScriptTemplates/SOEventTemplate.txt";
22+
private const string GenericSOEventListenerTemplatePath = "/CustomScriptTemplates/SOEventListenerTemplate.txt";
2623

2724
private static string _packageRelativePath;
2825
private static UnityEditor.PackageManager.PackageInfo _packageInfo;
@@ -92,17 +89,8 @@ public static void CreateSOEventScripts(string eventSOName, string eventListener
9289
private static void CreateSOEventScript(string creationPath, string eventName, string listenerName, string eventNamespace, string[] argTypes)
9390
{
9491
//1-Load template asset
95-
TextAsset soEventTemplate;
96-
if (argTypes!= null)
97-
{
98-
soEventTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
99-
+ GenericSOEventTemplatePath, typeof(TextAsset)) as TextAsset;
100-
}
101-
else
102-
{
103-
soEventTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
104-
+ NoArgsSOEventTemplatePath, typeof(TextAsset)) as TextAsset;
105-
}
92+
var soEventTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
93+
+ GenericSOEventTemplatePath, typeof(TextAsset)) as TextAsset;
10694

10795
//2-Check loaded object validity. If not valid, abort execution
10896
Assert.IsTrue(soEventTemplate != null, "[AssetCreation] SOEventTemplate loading failed. Aborting");
@@ -116,12 +104,14 @@ private static void CreateSOEventScript(string creationPath, string eventName, s
116104

117105
contents = ReplaceNamespaceTag(eventNamespace, contents);
118106

119-
//Event order?
120-
contents = contents.Replace("<LISTENER_NAME>", listenerName);
121107
if(argTypes != null){
122-
contents = contents.Replace("<ARGUMENT_LIST_DEFINITION>", argTypes[0]);
123-
contents = contents.Replace("<ARGUMENT_LIST>", argTypes[1]);
124108
contents = contents.Replace("<CUSTOM_NAMESPACE_LIST>", argTypes[3]);
109+
contents = contents.Replace("<ARGUMENT_TYPE_LIST>", $"<{argTypes[2]}>");
110+
}
111+
else
112+
{
113+
contents = contents.Replace("<CUSTOM_NAMESPACE_LIST>", string.Empty);
114+
contents = contents.Replace("<ARGUMENT_TYPE_LIST>", string.Empty);
125115
}
126116

127117
contents = FinalizeIndent(contents);
@@ -142,18 +132,8 @@ private static void CreateSOEventScript(string creationPath, string eventName, s
142132
private static void CreateSOEventListenerScript(string creationPath, string eventName, string listenerName, string eventNamespace, string[] argTypes)
143133
{
144134
//1-Load template asset
145-
TextAsset soEventListenerTemplate;
146-
if (argTypes != null)
147-
{
148-
soEventListenerTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
149-
+ GenericSOEventListenerTemplatePath, typeof(TextAsset)) as TextAsset;
150-
151-
}
152-
else
153-
{
154-
soEventListenerTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
155-
+ NoArgsSOEventListenerTemplatePath, typeof(TextAsset)) as TextAsset;
156-
}
135+
var soEventListenerTemplate = AssetDatabase.LoadAssetAtPath(_packageRelativePath
136+
+ GenericSOEventListenerTemplatePath, typeof(TextAsset)) as TextAsset;
157137

158138
//2-Check loaded object validity. If not valid, abort execution
159139
Assert.IsTrue(soEventListenerTemplate != null, "[AssetCreation] SOEventTemplate loading failed. Aborting");
@@ -163,16 +143,18 @@ private static void CreateSOEventListenerScript(string creationPath, string even
163143

164144
contents = contents.Replace("<SCRIPT_NAME>", listenerName);
165145
contents = contents.Replace("<SO_EVENT_NAME>", eventName);
166-
contents = contents.Replace("<SO_EVENT_FIELD_NAME>", eventName.Replace("SO", "so"));
167146

168147
contents = ReplaceNamespaceTag(eventNamespace, contents);
169148

170149
if (argTypes != null)
171150
{
172-
contents = contents.Replace("<ARGUMENT_LIST_DEFINITION>", argTypes[0]);
173-
contents = contents.Replace("<ARGUMENT_LIST>", argTypes[1]);
174-
contents = contents.Replace("<ARGUMENT_TYPE_LIST>", argTypes[2]);
175151
contents = contents.Replace("<CUSTOM_NAMESPACE_LIST>", argTypes[3]);
152+
contents = contents.Replace("<ARGUMENT_TYPE_LIST>", $", {argTypes[2]}");
153+
}
154+
else
155+
{
156+
contents = contents.Replace("<CUSTOM_NAMESPACE_LIST>", string.Empty);
157+
contents = contents.Replace("<ARGUMENT_TYPE_LIST>", string.Empty);
176158
}
177159

178160
contents = FinalizeIndent(contents);
@@ -242,9 +224,9 @@ private static string[] GenerateEventArguments(ArgInfo[] argsList)
242224

243225
if (argCount < argsList.Length)
244226
{
245-
sb_definitions.Append(",");
246-
sb_argList.Append(",");
247-
sb_typeList.Append(",");
227+
sb_definitions.Append(", ");
228+
sb_argList.Append(", ");
229+
sb_typeList.Append(", ");
248230
}
249231

250232
argCount++;

0 commit comments

Comments
 (0)