Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit f1b822e

Browse files
Implemented raise button on listeners
1 parent 5313055 commit f1b822e

File tree

5 files changed

+51
-232
lines changed

5 files changed

+51
-232
lines changed

Assets/SO Architecture/Editor/Inspectors/BaseGameEventEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ protected virtual void OnEnable()
1717
}
1818
public override void OnInspectorGUI()
1919
{
20-
EditorGUI.BeginDisabledGroup(!Application.isPlaying);
20+
//EditorGUI.BeginDisabledGroup(!Application.isPlaying);
2121
DrawRaiseButton();
22-
EditorGUI.EndDisabledGroup();
22+
//EditorGUI.EndDisabledGroup();
2323

2424
_stackTrace.Draw();
2525

Assets/SO Architecture/Editor/Inspectors/BaseGameEventListenerEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public abstract class BaseGameEventListenerEditor : Editor
1111
private SerializedProperty _debugColor;
1212
private SerializedProperty _response;
1313

14+
protected abstract void DrawRaiseButton();
15+
1416
protected virtual void OnEnable()
1517
{
1618
_stackTrace = new StackTrace(Target, true);
@@ -27,6 +29,8 @@ public override void OnInspectorGUI()
2729

2830
EditorGUILayout.PropertyField(_response, new GUIContent("Response"));
2931

32+
DrawRaiseButton();
33+
3034
_stackTrace.Draw();
3135

3236
SOArchitectureBaseObjectEditor.DrawDescription(DeveloperDescrption);
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
using UnityEditor;
1+
using System.Reflection;
2+
using UnityEngine;
3+
using UnityEditor;
24

35
[CustomEditor(typeof(BaseGameEventListener<,>), true)]
46
public class GameEventListenerEditor : BaseGameEventListenerEditor
57
{
8+
private MethodInfo _raiseMethod;
9+
10+
protected override void OnEnable()
11+
{
12+
base.OnEnable();
13+
14+
_raiseMethod = target.GetType().BaseType.GetMethod("OnEventRaised");
15+
}
16+
protected override void DrawRaiseButton()
17+
{
18+
if (GUILayout.Button("Raise"))
19+
{
20+
_raiseMethod.Invoke(target, null);
21+
}
22+
}
623
}

Assets/SO Architecture/Editor/Inspectors/TypedGameEventEditor.cs

Lines changed: 5 additions & 228 deletions
Original file line numberDiff line numberDiff line change
@@ -8,244 +8,21 @@ public class TypedGameEventEditor : BaseGameEventEditor
88
private System.Type GenericType { get { return target.GetType().BaseType.GetGenericArguments()[0]; } }
99

1010
private MethodInfo _raiseMethod;
11-
private MutableObject _value = new MutableObject();
11+
private TypedRaiseButton _raiseButton;
1212

1313
protected override void OnEnable()
1414
{
1515
base.OnEnable();
1616

1717
_raiseMethod = target.GetType().BaseType.GetMethod("Raise");
18+
_raiseButton = new TypedRaiseButton(GenericType, CallMethod);
1819
}
1920
protected override void DrawRaiseButton()
2021
{
21-
if (GenericType == typeof(bool))
22-
{
23-
_value = EditorGUILayout.Toggle("Debug Value", _value);
24-
25-
RaiseButton((bool)_value);
26-
}
27-
else if (GenericType == typeof(byte))
28-
{
29-
_value = EditorGUILayout.IntField("Debug Value", _value);
30-
31-
RaiseButton((byte)_value);
32-
}
33-
else if (GenericType == typeof(char))
34-
{
35-
_value = EditorGUILayout.TextField("Debug Value", _value);
36-
37-
RaiseButton((char)_value);
38-
}
39-
else if (GenericType == typeof(double))
40-
{
41-
_value = EditorGUILayout.DoubleField("Debug Value", _value);
42-
43-
RaiseButton((double)_value);
44-
}
45-
else if (GenericType == typeof(float))
46-
{
47-
_value = EditorGUILayout.FloatField("Debug Value", _value);
48-
49-
RaiseButton((float)_value);
50-
}
51-
else if (GenericType == typeof(int))
52-
{
53-
_value = EditorGUILayout.IntField("Debug Value", _value);
54-
55-
RaiseButton((int)_value);
56-
}
57-
else if (GenericType == typeof(long))
58-
{
59-
_value = EditorGUILayout.LongField("Debug Value", _value);
60-
61-
RaiseButton((long)_value);
62-
}
63-
else if (GenericType == typeof(Object))
64-
{
65-
_value = EditorGUILayout.ObjectField("Debug Value", _value, GenericType, true);
66-
67-
RaiseButton((Object)_value);
68-
}
69-
else if (GenericType == typeof(sbyte))
70-
{
71-
_value = EditorGUILayout.IntField("Debug Value", _value);
72-
73-
RaiseButton((sbyte)_value);
74-
}
75-
else if (GenericType == typeof(short))
76-
{
77-
_value = EditorGUILayout.IntField("Debug Value", _value);
78-
79-
RaiseButton((short)_value);
80-
}
81-
else if (GenericType == typeof(string))
82-
{
83-
_value = EditorGUILayout.TextField("Debug Value", _value);
84-
85-
RaiseButton((string)_value);
86-
}
87-
else if (GenericType == typeof(uint))
88-
{
89-
_value = EditorGUILayout.LongField("Debug Value", _value);
90-
91-
RaiseButton((uint)(long)_value);
92-
}
93-
else if (GenericType == typeof(ushort))
94-
{
95-
_value = EditorGUILayout.IntField("Debug Value", _value);
96-
97-
RaiseButton((ushort)(int)_value);
98-
}
99-
else
100-
{
101-
EditorGUILayout.LabelField("Can't draw debug value field for " + GenericType);
102-
}
103-
}
104-
private void RaiseButton(object value)
105-
{
106-
if (GUILayout.Button("Raise"))
107-
{
108-
_raiseMethod.Invoke(target, new object[1] { value });
109-
}
22+
_raiseButton.Draw();
11023
}
111-
private partial class MutableObject
24+
private void CallMethod(object value)
11225
{
113-
public MutableObject() { }
114-
}
115-
private partial class MutableObject
116-
{
117-
public MutableObject(bool value)
118-
{
119-
_boolValue = value;
120-
}
121-
122-
private bool _boolValue;
123-
124-
public static implicit operator bool(MutableObject obj)
125-
{
126-
return obj._boolValue;
127-
}
128-
public static implicit operator MutableObject(bool value)
129-
{
130-
return new MutableObject(value);
131-
}
132-
}
133-
private partial class MutableObject
134-
{
135-
public MutableObject(int value)
136-
{
137-
_intValue = value;
138-
}
139-
140-
private int _intValue;
141-
142-
public static implicit operator int(MutableObject obj)
143-
{
144-
return obj._intValue;
145-
}
146-
public static implicit operator MutableObject(int value)
147-
{
148-
return new MutableObject(value);
149-
}
150-
}
151-
private partial class MutableObject
152-
{
153-
public MutableObject(float value)
154-
{
155-
_floatValue = value;
156-
}
157-
158-
private float _floatValue;
159-
160-
public static implicit operator float(MutableObject obj)
161-
{
162-
return obj._floatValue;
163-
}
164-
public static implicit operator MutableObject(float value)
165-
{
166-
return new MutableObject(value);
167-
}
168-
}
169-
private partial class MutableObject
170-
{
171-
public MutableObject(string value)
172-
{
173-
_stringValue = value;
174-
}
175-
176-
private string _stringValue;
177-
178-
public static implicit operator string(MutableObject obj)
179-
{
180-
return obj._stringValue;
181-
}
182-
public static implicit operator char(MutableObject obj)
183-
{
184-
if (obj._stringValue == null)
185-
return default(char);
186-
187-
if (obj._stringValue.Length > 0)
188-
return obj._stringValue[0];
189-
190-
return default(char);
191-
}
192-
public static implicit operator MutableObject(string value)
193-
{
194-
return new MutableObject(value);
195-
}
196-
}
197-
private partial class MutableObject
198-
{
199-
public MutableObject(double value)
200-
{
201-
_doubleValue = value;
202-
}
203-
204-
private double _doubleValue;
205-
206-
public static implicit operator double(MutableObject obj)
207-
{
208-
return obj._doubleValue;
209-
}
210-
public static implicit operator MutableObject(double value)
211-
{
212-
return new MutableObject(value);
213-
}
214-
}
215-
private partial class MutableObject
216-
{
217-
public MutableObject(long value)
218-
{
219-
_longValue = value;
220-
}
221-
222-
private long _longValue;
223-
224-
public static implicit operator long(MutableObject obj)
225-
{
226-
return obj._longValue;
227-
}
228-
public static implicit operator MutableObject(long value)
229-
{
230-
return new MutableObject(value);
231-
}
232-
}
233-
private partial class MutableObject
234-
{
235-
public MutableObject(Object value)
236-
{
237-
_objectValue = value;
238-
}
239-
240-
private Object _objectValue;
241-
242-
public static implicit operator Object(MutableObject obj)
243-
{
244-
return obj._objectValue;
245-
}
246-
public static implicit operator MutableObject(Object value)
247-
{
248-
return new MutableObject(value);
249-
}
26+
_raiseMethod.Invoke(target, new object[1] { value });
25027
}
25128
}
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
using UnityEditor;
1+
using System.Reflection;
2+
using UnityEditor;
23

34
[CustomEditor(typeof(BaseGameEventListener<,,>), true)]
45
public class TypesGameEventListenerEditor : BaseGameEventListenerEditor
56
{
7+
private System.Type GenericType { get { return target.GetType().BaseType.GetGenericArguments()[0]; } }
8+
9+
private MethodInfo _raiseMethod;
10+
private TypedRaiseButton _raiseButton;
11+
12+
protected override void OnEnable()
13+
{
14+
base.OnEnable();
15+
16+
_raiseMethod = target.GetType().BaseType.GetMethod("OnEventRaised");
17+
_raiseButton = new TypedRaiseButton(GenericType, CallMethod);
18+
}
19+
protected override void DrawRaiseButton()
20+
{
21+
_raiseButton.Draw();
22+
}
23+
private void CallMethod(object value)
24+
{
25+
_raiseMethod.Invoke(target, new object[1] { value });
26+
}
627
}

0 commit comments

Comments
 (0)