Skip to content

Commit 79366d9

Browse files
authored
Merge pull request #1 from danigfedev/Code_Review_2026
SO Event Creation window redesign and code improvements and cleanup
2 parents 334b2b1 + d48b904 commit 79366d9

36 files changed

+1000
-342
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
README.md.meta

CustomScriptTemplates/GenericSOEventListenerTemplate.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.Events;
3-
3+
<CUSTOM_NAMESPACE_LIST>
4+
<NAMESPACE_DECLARATION_START>
45
public class <SCRIPT_NAME> : MonoBehaviour
56
{
67
[System.Serializable]
@@ -19,9 +20,9 @@ public class <SCRIPT_NAME> : MonoBehaviour
1920
<SO_EVENT_FIELD_NAME>.RemoveListener(this);
2021
}
2122

22-
public void RiseEvent(<ARGUMENT_LIST_DEFINITION>)//Type1 arg1, Type2 arg2, Type3 arg3...
23+
public void RiseEvent(<ARGUMENT_LIST_DEFINITION>) //Type1 arg1, Type2 arg2, Type3 arg3...
2324
{
2425
response.Invoke(<ARGUMENT_LIST>); //arg1, arg2, arg3...
2526
}
26-
2727
}
28+
<NAMESPACE_DECLARATION_END>
Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
using System.Collections.Generic;
22
using UnityEngine;
3-
3+
<CUSTOM_NAMESPACE_LIST>
4+
<NAMESPACE_DECLARATION_START>
45
[CreateAssetMenu(fileName ="<SO_FILE_NAME>", menuName ="EspidiGames/SO Events/<SO_MENU_NAME>", order = 20)]
56
public class <SCRIPT_NAME> : ScriptableObject
67
{
78
private List<<LISTENER_NAME>> listeners = new List<<LISTENER_NAME>>();
89

9-
10-
public void AddListener(<LISTENER_NAME> l)
10+
public void AddListener(<LISTENER_NAME> listener)
1111
{
12-
if (listeners.Contains(l))
12+
if (listeners.Contains(listener))
1313
{
14-
Debug.LogError($"[ScriptableObjectEvents] Listener {l.name} of GameObject {l.gameObject.name} already registered. Aborting registration.");
14+
Debug.LogError($"[ScriptableObjectEvents] Listener {listener.name} of GameObject {listener.gameObject.name} already registered. Aborting registration.");
1515
return;
1616
}
1717

18-
listeners.Add(l);
18+
listeners.Add(listener);
1919
}
2020

21-
public void RemoveListener(<LISTENER_NAME> l)
21+
public void RemoveListener(<LISTENER_NAME> listener)
2222
{
23-
if (!listeners.Contains(l))
23+
if (!listeners.Contains(listener))
2424
{
25-
Debug.LogError($"[ScriptableObjectEvents] Listener {l.name} of GameObject {l.gameObject.name} is not registered. Aborting removal.");
25+
Debug.LogError($"[ScriptableObjectEvents] Listener {listener.name} of GameObject {listener.gameObject.name} is not registered. Aborting removal.");
2626
return;
2727
}
2828

29-
listeners.Remove(l);
29+
listeners.Remove(listener);
3030
}
3131

3232
public void RiseEvent(<ARGUMENT_LIST_DEFINITION>) //Type1 arg1, Type2 arg2, Type3 arg3...
@@ -37,3 +37,4 @@ public class <SCRIPT_NAME> : ScriptableObject
3737
}
3838
}
3939
}
40+
<NAMESPACE_DECLARATION_END>

CustomScriptTemplates/NoArgsSOEventListenerTemplate.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.Events;
33

4+
<NAMESPACE_DECLARATION_START>
45
public class <SCRIPT_NAME> : MonoBehaviour
56
{
67
[SerializeField] private <SO_EVENT_NAME> <SO_EVENT_FIELD_NAME>;
@@ -20,5 +21,5 @@ public class <SCRIPT_NAME> : MonoBehaviour
2021
{
2122
response.Invoke();
2223
}
23-
2424
}
25+
<NAMESPACE_DECLARATION_END>
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33

4+
<NAMESPACE_DECLARATION_START>
45
[CreateAssetMenu(fileName ="<SO_FILE_NAME>", menuName ="EspidiGames/SO Events/<SO_MENU_NAME>", order = 20)]
56
public class <SCRIPT_NAME> : ScriptableObject
67
{
78
private List<<LISTENER_NAME>> listeners = new List<<LISTENER_NAME>>();
89

9-
10-
public void AddListener(<LISTENER_NAME> l)
10+
public void AddListener(<LISTENER_NAME> listener)
1111
{
12-
if (listeners.Contains(l))
12+
if (listeners.Contains(listener))
1313
{
14-
Debug.LogError($"[ScriptableObjectEvents] Listener {l.name} of GameObject {l.gameObject.name} already registered. Aborting registration.");
14+
Debug.LogError($"[ScriptableObjectEvents] Listener {listener.name} of GameObject {listener.gameObject.name} already registered. Aborting registration.");
1515
return;
1616
}
1717

18-
listeners.Add(l);
18+
listeners.Add(listener);
1919
}
2020

21-
public void RemoveListener(<LISTENER_NAME> l)
21+
public void RemoveListener(<LISTENER_NAME> listener)
2222
{
23-
if (!listeners.Contains(l))
23+
if (!listeners.Contains(listener))
2424
{
25-
Debug.LogError($"[ScriptableObjectEvents] Listener {l.name} of GameObject {l.gameObject.name} is not registered. Aborting removal.");
25+
Debug.LogError($"[ScriptableObjectEvents] Listener {listener.name} of GameObject {listener.gameObject.name} is not registered. Aborting removal.");
2626
return;
2727
}
2828

29-
listeners.Remove(l);
29+
listeners.Remove(listener);
3030
}
3131

3232
public void RiseEvent()
@@ -37,3 +37,4 @@ public class <SCRIPT_NAME> : ScriptableObject
3737
}
3838
}
3939
}
40+
<NAMESPACE_DECLARATION_END>

Editor/ArgInfo.cs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using UnityEngine;
2+
3+
namespace EG.ScriptableObjectSystem.Editor
4+
{
5+
public class ArgInfo
6+
{
7+
public EventSupportedArgs SupportedType { get; private set; }
8+
public string ArgType { get; private set; }
9+
public string ArgNamespace { get; private set; }
10+
11+
public static ArgInfo CreateStandardArg()
12+
{
13+
return new ArgInfo(EventSupportedArgs.Int);
14+
}
15+
16+
public static ArgInfo CreateStandardArg(EventSupportedArgs supportedType)
17+
{
18+
return new ArgInfo(supportedType);
19+
}
20+
21+
public static ArgInfo CreateCustomTypeArg(string argType, string argNamespace)
22+
{
23+
return new ArgInfo(EventSupportedArgs.Custom, argType, argNamespace);
24+
}
25+
26+
public void UpdateInfo(EventSupportedArgs supportedType, string customArgType = null, string argNamespace = null)
27+
{
28+
if (supportedType != EventSupportedArgs.Custom)
29+
{
30+
if (!string.IsNullOrEmpty(customArgType))
31+
{
32+
Debug.LogWarning("You´re marking the Arg as standard Type. Custom Arg Type and its namespace are not required and will be ignored.");
33+
}
34+
35+
SetStandardType(supportedType);
36+
}
37+
else
38+
{
39+
if (string.IsNullOrEmpty(customArgType))
40+
{
41+
Debug.LogWarning("You´re updating the Arg Info with Custom type. You must provide the Type and, optionally, its namespace");
42+
}
43+
44+
SetCustomType(supportedType, customArgType, argNamespace);
45+
}
46+
}
47+
48+
public void ForceCustomArg()
49+
{
50+
SetCustomType(EventSupportedArgs.Custom, null, null);
51+
}
52+
53+
private ArgInfo(EventSupportedArgs supportedType)
54+
{
55+
SetStandardType(supportedType);
56+
}
57+
58+
private ArgInfo(EventSupportedArgs supportedType, string customArgType, string argNamespace)
59+
{
60+
SetCustomType(supportedType, customArgType, argNamespace);
61+
}
62+
63+
private void SetStandardType(EventSupportedArgs supportedType)
64+
{
65+
SupportedType = supportedType;
66+
ArgType = SupportedType.ToString().ToLower();
67+
}
68+
69+
private void SetCustomType(EventSupportedArgs supportedType, string customArgType, string argNamespace)
70+
{
71+
SupportedType = supportedType;
72+
ArgType = customArgType;
73+
ArgNamespace = argNamespace;
74+
}
75+
}
76+
}

Editor/ArgInfo.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)