@@ -8,244 +8,21 @@ public class TypedGameEventEditor : BaseGameEventEditor
8
8
private System . Type GenericType { get { return target . GetType ( ) . BaseType . GetGenericArguments ( ) [ 0 ] ; } }
9
9
10
10
private MethodInfo _raiseMethod ;
11
- private MutableObject _value = new MutableObject ( ) ;
11
+ private TypedRaiseButton _raiseButton ;
12
12
13
13
protected override void OnEnable ( )
14
14
{
15
15
base . OnEnable ( ) ;
16
16
17
17
_raiseMethod = target . GetType ( ) . BaseType . GetMethod ( "Raise" ) ;
18
+ _raiseButton = new TypedRaiseButton ( GenericType , CallMethod ) ;
18
19
}
19
20
protected override void DrawRaiseButton ( )
20
21
{
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 ( ) ;
110
23
}
111
- private partial class MutableObject
24
+ private void CallMethod ( object value )
112
25
{
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 } ) ;
250
27
}
251
28
}
0 commit comments