@@ -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