|
@@ -0,0 +1,879 @@
|
|
1
|
+using System.Collections;
|
|
2
|
+using System.Collections.Generic;
|
|
3
|
+using UnityEngine;
|
|
4
|
+using UnityEditor;
|
|
5
|
+using System;
|
|
6
|
+using UnityEditor.SceneManagement;
|
|
7
|
+using System.Reflection;
|
|
8
|
+using UObject = UnityEngine.Object;
|
|
9
|
+using UnityEngine.UIElements;
|
|
10
|
+
|
|
11
|
+namespace TModule.Editor
|
|
12
|
+{
|
|
13
|
+ [CustomEditor(typeof(UObject),true)]
|
|
14
|
+ public class ObjectInspector : UnityEditor.Editor
|
|
15
|
+ {
|
|
16
|
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|
17
|
+ List<MethodDrawer> methodDrawers = new List<MethodDrawer>();
|
|
18
|
+ List<PropertyInfo> propertyInfos = new List<PropertyInfo>();
|
|
19
|
+ List<PropertyDrawer> propertyDrawers = new List<PropertyDrawer>();
|
|
20
|
+ Dictionary<Type,Type> methodDrawerTypes = new Dictionary<Type,Type>();
|
|
21
|
+ Dictionary<Type, Type> propertyDrawerTypes = new Dictionary<Type, Type>();
|
|
22
|
+
|
|
23
|
+ private void OnEnable()
|
|
24
|
+ {
|
|
25
|
+ foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
|
26
|
+ {
|
|
27
|
+ foreach (var type in assembly.GetTypes())
|
|
28
|
+ {
|
|
29
|
+ if (type.IsDefined(typeof(CustomMethodDrawerAttribute), true))
|
|
30
|
+ {
|
|
31
|
+ Type type1 = type.GetCustomAttribute<CustomMethodDrawerAttribute>().AttributeType;
|
|
32
|
+ if (methodDrawerTypes.ContainsKey(type1))
|
|
33
|
+ methodDrawerTypes[type1] = type;
|
|
34
|
+ else
|
|
35
|
+ methodDrawerTypes.Add(type1, type);
|
|
36
|
+ }
|
|
37
|
+ if (type.IsDefined(typeof(TCustomPropertyDrawerAttribute), true))
|
|
38
|
+ {
|
|
39
|
+ Type type1 = type.GetCustomAttribute<TCustomPropertyDrawerAttribute>().AttributeType;
|
|
40
|
+ if (propertyDrawerTypes.ContainsKey(type1))
|
|
41
|
+ propertyDrawerTypes[type1] = type;
|
|
42
|
+ else
|
|
43
|
+ propertyDrawerTypes.Add(type1, type);
|
|
44
|
+ }
|
|
45
|
+ }
|
|
46
|
+ }
|
|
47
|
+ foreach (var method in target.GetType().GetMethods(flags))
|
|
48
|
+ {
|
|
49
|
+ if(method.IsDefined(typeof(MethodAttribute), true))
|
|
50
|
+ {
|
|
51
|
+ MethodAttribute attribute = method.GetCustomAttribute<MethodAttribute>();
|
|
52
|
+ if (!methodDrawerTypes.ContainsKey(attribute.GetType())) continue;
|
|
53
|
+ MethodDrawer methodDrawer = Activator.CreateInstance(methodDrawerTypes[attribute.GetType()]) as MethodDrawer;
|
|
54
|
+ if (methodDrawer != null)
|
|
55
|
+ {
|
|
56
|
+ methodDrawer.attribute = attribute;
|
|
57
|
+ methodDrawer.methodInfo = method;
|
|
58
|
+ methodDrawers.Add(methodDrawer);
|
|
59
|
+ }
|
|
60
|
+ }
|
|
61
|
+ }
|
|
62
|
+ foreach (var property in target.GetType().GetProperties(flags))
|
|
63
|
+ {
|
|
64
|
+ if (property.IsDefined(typeof(PropertyAttribute), true))
|
|
65
|
+ {
|
|
66
|
+ PropertyAttribute attribute = property.GetCustomAttribute<PropertyAttribute>();
|
|
67
|
+ if (!propertyDrawerTypes.ContainsKey(attribute.GetType())) continue;
|
|
68
|
+ PropertyDrawer propertyDrawer = Activator.CreateInstance(propertyDrawerTypes[attribute.GetType()]) as PropertyDrawer;
|
|
69
|
+ if (propertyDrawer != null)
|
|
70
|
+ {
|
|
71
|
+ propertyDrawer.attribute = attribute;
|
|
72
|
+ propertyDrawer.propertyInfo = property;
|
|
73
|
+ propertyDrawers.Add(propertyDrawer);
|
|
74
|
+ }
|
|
75
|
+ }
|
|
76
|
+ }
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ public override void OnInspectorGUI()
|
|
80
|
+ {
|
|
81
|
+ base.OnInspectorGUI();
|
|
82
|
+ foreach (var property in propertyDrawers)
|
|
83
|
+ {
|
|
84
|
+ property.OnGUI(serializedObject);
|
|
85
|
+ }
|
|
86
|
+ foreach (var method in methodDrawers)
|
|
87
|
+ {
|
|
88
|
+ method.OnGUI(serializedObject);
|
|
89
|
+ }
|
|
90
|
+ }
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ public abstract class BaseAttributeDrawer : UnityEditor.PropertyDrawer
|
|
94
|
+ {
|
|
95
|
+ Rect copyRect = Rect.zero;
|
|
96
|
+ Rect pasteRect = Rect.zero;
|
|
97
|
+ public UObject target;
|
|
98
|
+
|
|
99
|
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
100
|
+ {
|
|
101
|
+ InspectorAttribute _attribute = (InspectorAttribute)attribute;
|
|
102
|
+ if (_attribute is BegingFoldAttribute && property.isExpanded)
|
|
103
|
+ {
|
|
104
|
+ if (_attribute.IsShow)
|
|
105
|
+ return base.GetPropertyHeight(property, label);
|
|
106
|
+ else
|
|
107
|
+ return 0;
|
|
108
|
+ }
|
|
109
|
+ else
|
|
110
|
+ return base.GetPropertyHeight(property, label);
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
114
|
+ {
|
|
115
|
+ if (property != null) target = property.serializedObject.targetObject;
|
|
116
|
+
|
|
117
|
+ InspectorAttribute _attribute = (InspectorAttribute)attribute;
|
|
118
|
+ OnDarwBefore(position, property, label);
|
|
119
|
+ if (!_attribute.IsShow) return;
|
|
120
|
+ if (_attribute is BegingFoldAttribute && !property.isExpanded) return;
|
|
121
|
+
|
|
122
|
+ float _width = position.width;
|
|
123
|
+ _width -= (Convert.ToInt32(_attribute.IsEnableCopy) + Convert.ToInt32(_attribute.IsEnadlePaste)) * 43;
|
|
124
|
+ float _btnWidth = _width;
|
|
125
|
+ if (_attribute.IsEnableCopy)
|
|
126
|
+ {
|
|
127
|
+ _btnWidth += 23;
|
|
128
|
+ copyRect.Set(_btnWidth, position.y, 40, position.height);
|
|
129
|
+ if (GUI.Button(copyRect, "¸´ÖÆ"))
|
|
130
|
+ Copy(property);
|
|
131
|
+ _btnWidth += 43;
|
|
132
|
+ }
|
|
133
|
+ if(_attribute.IsEnadlePaste)
|
|
134
|
+ {
|
|
135
|
+ pasteRect.Set(_btnWidth, position.y, 40, position.height);
|
|
136
|
+ if (GUI.Button(pasteRect, "Õ³Ìù"))
|
|
137
|
+ Paste(property);
|
|
138
|
+ }
|
|
139
|
+
|
|
140
|
+ position.width = _width;
|
|
141
|
+ switch (_attribute.DrawMode)
|
|
142
|
+ {
|
|
143
|
+ case DrawMode.EditModeAndRunTime:
|
|
144
|
+ OnDarw(position, property, label);
|
|
145
|
+ break;
|
|
146
|
+ case DrawMode.OnlyEditMode:
|
|
147
|
+ if (!EditorApplication.isPlaying)
|
|
148
|
+ OnDarwEditMode(position, property, label);
|
|
149
|
+ break;
|
|
150
|
+ case DrawMode.OnlyRuntime:
|
|
151
|
+ if (EditorApplication.isPlaying)
|
|
152
|
+ OnDarwRuntime(position, property, label);
|
|
153
|
+ break;
|
|
154
|
+ default:
|
|
155
|
+ base.OnGUI(position, property, label);
|
|
156
|
+ break;
|
|
157
|
+ }
|
|
158
|
+
|
|
159
|
+ }
|
|
160
|
+
|
|
161
|
+ public virtual void OnDarwBefore(Rect position, SerializedProperty property, GUIContent label)
|
|
162
|
+ {
|
|
163
|
+
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+ public virtual void Paste(SerializedProperty property)
|
|
167
|
+ {
|
|
168
|
+ property.serializedObject.Update();
|
|
169
|
+ switch (property.propertyType)
|
|
170
|
+ {
|
|
171
|
+ case SerializedPropertyType.Generic:
|
|
172
|
+ break;
|
|
173
|
+ case SerializedPropertyType.Integer:
|
|
174
|
+ if (int.TryParse(EditorGUIUtility.systemCopyBuffer, out int v))
|
|
175
|
+ property.intValue = v;
|
|
176
|
+ break;
|
|
177
|
+ case SerializedPropertyType.Boolean:
|
|
178
|
+ if (bool.TryParse(EditorGUIUtility.systemCopyBuffer, out bool b))
|
|
179
|
+ property.boolValue = b;
|
|
180
|
+ break;
|
|
181
|
+ case SerializedPropertyType.Float:
|
|
182
|
+ string fstr = EditorGUIUtility.systemCopyBuffer.Replace("f", "");
|
|
183
|
+ if (float.TryParse(fstr, out float f))
|
|
184
|
+ property.floatValue = f;
|
|
185
|
+ break;
|
|
186
|
+ case SerializedPropertyType.String:
|
|
187
|
+ property.stringValue = EditorGUIUtility.systemCopyBuffer;
|
|
188
|
+ break;
|
|
189
|
+ case SerializedPropertyType.Color:
|
|
190
|
+ property.colorValue = JsonUtility.FromJson<Color>(EditorGUIUtility.systemCopyBuffer);
|
|
191
|
+ break;
|
|
192
|
+ case SerializedPropertyType.ObjectReference:
|
|
193
|
+ property.objectReferenceValue = JsonUtility.FromJson<UnityEngine.Object>(EditorGUIUtility.systemCopyBuffer);
|
|
194
|
+ break;
|
|
195
|
+ case SerializedPropertyType.LayerMask:
|
|
196
|
+ break;
|
|
197
|
+ case SerializedPropertyType.Enum:
|
|
198
|
+ property.enumValueIndex = JsonUtility.FromJson<int>(EditorGUIUtility.systemCopyBuffer);
|
|
199
|
+ break;
|
|
200
|
+ case SerializedPropertyType.Vector2:
|
|
201
|
+ property.vector2Value = JsonUtility.FromJson<Vector2>(EditorGUIUtility.systemCopyBuffer);
|
|
202
|
+ break;
|
|
203
|
+ case SerializedPropertyType.Vector3:
|
|
204
|
+ property.vector3Value = JsonUtility.FromJson<Vector3>(EditorGUIUtility.systemCopyBuffer);
|
|
205
|
+ break;
|
|
206
|
+ case SerializedPropertyType.Vector4:
|
|
207
|
+ property.vector4Value = JsonUtility.FromJson<Vector4>(EditorGUIUtility.systemCopyBuffer);
|
|
208
|
+ break;
|
|
209
|
+ case SerializedPropertyType.Rect:
|
|
210
|
+ property.rectValue = JsonUtility.FromJson<Rect>(EditorGUIUtility.systemCopyBuffer);
|
|
211
|
+ break;
|
|
212
|
+ case SerializedPropertyType.ArraySize:
|
|
213
|
+ property.arraySize = JsonUtility.FromJson<int>(EditorGUIUtility.systemCopyBuffer);
|
|
214
|
+ break;
|
|
215
|
+ case SerializedPropertyType.Character:
|
|
216
|
+ break;
|
|
217
|
+ case SerializedPropertyType.AnimationCurve:
|
|
218
|
+ property.animationCurveValue = JsonUtility.FromJson<AnimationCurve>(EditorGUIUtility.systemCopyBuffer);
|
|
219
|
+ break;
|
|
220
|
+ case SerializedPropertyType.Bounds:
|
|
221
|
+ property.boundsValue = JsonUtility.FromJson<Bounds>(EditorGUIUtility.systemCopyBuffer);
|
|
222
|
+ break;
|
|
223
|
+ case SerializedPropertyType.Gradient:
|
|
224
|
+ break;
|
|
225
|
+ case SerializedPropertyType.Quaternion:
|
|
226
|
+ property.quaternionValue = JsonUtility.FromJson<Quaternion>(EditorGUIUtility.systemCopyBuffer);
|
|
227
|
+ break;
|
|
228
|
+ case SerializedPropertyType.ExposedReference:
|
|
229
|
+ property.exposedReferenceValue = JsonUtility.FromJson<UnityEngine.Object>(EditorGUIUtility.systemCopyBuffer);
|
|
230
|
+ break;
|
|
231
|
+ case SerializedPropertyType.FixedBufferSize:
|
|
232
|
+ break;
|
|
233
|
+ case SerializedPropertyType.Vector2Int:
|
|
234
|
+ property.vector2IntValue = JsonUtility.FromJson<Vector2Int>(EditorGUIUtility.systemCopyBuffer);
|
|
235
|
+ break;
|
|
236
|
+ case SerializedPropertyType.Vector3Int:
|
|
237
|
+ property.vector3IntValue = JsonUtility.FromJson<Vector3Int>(EditorGUIUtility.systemCopyBuffer);
|
|
238
|
+ break;
|
|
239
|
+ case SerializedPropertyType.RectInt:
|
|
240
|
+ property.rectIntValue = JsonUtility.FromJson<RectInt>(EditorGUIUtility.systemCopyBuffer);
|
|
241
|
+ break;
|
|
242
|
+ case SerializedPropertyType.BoundsInt:
|
|
243
|
+ property.boundsIntValue = JsonUtility.FromJson<BoundsInt>(EditorGUIUtility.systemCopyBuffer);
|
|
244
|
+ break;
|
|
245
|
+ case SerializedPropertyType.ManagedReference:
|
|
246
|
+ property.managedReferenceValue = JsonUtility.FromJson<object>(EditorGUIUtility.systemCopyBuffer);
|
|
247
|
+ break;
|
|
248
|
+ case SerializedPropertyType.Hash128:
|
|
249
|
+ property.hash128Value = JsonUtility.FromJson<Hash128>(EditorGUIUtility.systemCopyBuffer);
|
|
250
|
+ break;
|
|
251
|
+ default:
|
|
252
|
+ break;
|
|
253
|
+ }
|
|
254
|
+ property.serializedObject.ApplyModifiedProperties();
|
|
255
|
+ }
|
|
256
|
+
|
|
257
|
+ public virtual void Copy(SerializedProperty property)
|
|
258
|
+ {
|
|
259
|
+ switch (property.propertyType)
|
|
260
|
+ {
|
|
261
|
+ case SerializedPropertyType.Generic:
|
|
262
|
+ break;
|
|
263
|
+ case SerializedPropertyType.Integer:
|
|
264
|
+ EditorGUIUtility.systemCopyBuffer=property.intValue.ToString();
|
|
265
|
+ break;
|
|
266
|
+ case SerializedPropertyType.Boolean:
|
|
267
|
+ EditorGUIUtility.systemCopyBuffer = property.boolValue.ToString();
|
|
268
|
+ break;
|
|
269
|
+ case SerializedPropertyType.Float:
|
|
270
|
+ EditorGUIUtility.systemCopyBuffer = property.floatValue + "f";
|
|
271
|
+ break;
|
|
272
|
+ case SerializedPropertyType.String:
|
|
273
|
+ EditorGUIUtility.systemCopyBuffer = property.stringValue;
|
|
274
|
+ break;
|
|
275
|
+ case SerializedPropertyType.Color:
|
|
276
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.colorValue);
|
|
277
|
+ break;
|
|
278
|
+ case SerializedPropertyType.ObjectReference:
|
|
279
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.objectReferenceValue);
|
|
280
|
+ break;
|
|
281
|
+ case SerializedPropertyType.LayerMask:
|
|
282
|
+ break;
|
|
283
|
+ case SerializedPropertyType.Enum:
|
|
284
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.enumValueIndex);
|
|
285
|
+ break;
|
|
286
|
+ case SerializedPropertyType.Vector2:
|
|
287
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.vector2Value);
|
|
288
|
+ break;
|
|
289
|
+ case SerializedPropertyType.Vector3:
|
|
290
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.vector3Value);
|
|
291
|
+ break;
|
|
292
|
+ case SerializedPropertyType.Vector4:
|
|
293
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.vector4Value);
|
|
294
|
+ break;
|
|
295
|
+ case SerializedPropertyType.Rect:
|
|
296
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.rectValue);
|
|
297
|
+ break;
|
|
298
|
+ case SerializedPropertyType.ArraySize:
|
|
299
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.arraySize);
|
|
300
|
+ break;
|
|
301
|
+ case SerializedPropertyType.Character:
|
|
302
|
+ break;
|
|
303
|
+ case SerializedPropertyType.AnimationCurve:
|
|
304
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.animationCurveValue);
|
|
305
|
+ break;
|
|
306
|
+ case SerializedPropertyType.Bounds:
|
|
307
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.boundsValue);
|
|
308
|
+ break;
|
|
309
|
+ case SerializedPropertyType.Gradient:
|
|
310
|
+ break;
|
|
311
|
+ case SerializedPropertyType.Quaternion:
|
|
312
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.quaternionValue);
|
|
313
|
+ break;
|
|
314
|
+ case SerializedPropertyType.ExposedReference:
|
|
315
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.exposedReferenceValue);
|
|
316
|
+ break;
|
|
317
|
+ case SerializedPropertyType.FixedBufferSize:
|
|
318
|
+ break;
|
|
319
|
+ case SerializedPropertyType.Vector2Int:
|
|
320
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.vector2IntValue);
|
|
321
|
+ break;
|
|
322
|
+ case SerializedPropertyType.Vector3Int:
|
|
323
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.vector3IntValue);
|
|
324
|
+ break;
|
|
325
|
+ case SerializedPropertyType.RectInt:
|
|
326
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.rectIntValue);
|
|
327
|
+ break;
|
|
328
|
+ case SerializedPropertyType.BoundsInt:
|
|
329
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.boundsIntValue);
|
|
330
|
+ break;
|
|
331
|
+ case SerializedPropertyType.ManagedReference:
|
|
332
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.managedReferenceValue);
|
|
333
|
+ break;
|
|
334
|
+ case SerializedPropertyType.Hash128:
|
|
335
|
+ EditorGUIUtility.systemCopyBuffer = JsonUtility.ToJson(property.hash128Value);
|
|
336
|
+ break;
|
|
337
|
+ default:
|
|
338
|
+ break;
|
|
339
|
+ }
|
|
340
|
+ }
|
|
341
|
+
|
|
342
|
+ public virtual void OnDarwRuntime(Rect position, SerializedProperty property, GUIContent label)
|
|
343
|
+ {
|
|
344
|
+ DrawUI(position, property, label);
|
|
345
|
+ }
|
|
346
|
+
|
|
347
|
+ public virtual void OnDarwEditMode(Rect position, SerializedProperty property, GUIContent label)
|
|
348
|
+ {
|
|
349
|
+ DrawUI(position, property, label);
|
|
350
|
+ }
|
|
351
|
+
|
|
352
|
+ public virtual void OnDarw(Rect position, SerializedProperty property, GUIContent label)
|
|
353
|
+ {
|
|
354
|
+ DrawUI(position, property, label);
|
|
355
|
+ }
|
|
356
|
+
|
|
357
|
+ public abstract void DrawUI(Rect position, SerializedProperty property, GUIContent label);
|
|
358
|
+
|
|
359
|
+ public void MarkerChange()
|
|
360
|
+ {
|
|
361
|
+ if (target == null) return;
|
|
362
|
+ EditorUtility.SetDirty(target);
|
|
363
|
+ if (EditorApplication.isPlaying) return;
|
|
364
|
+
|
|
365
|
+ Component component = target as Component;
|
|
366
|
+ if (component != null && component.gameObject.scene != null)
|
|
367
|
+ {
|
|
368
|
+ EditorSceneManager.MarkSceneDirty(component.gameObject.scene);
|
|
369
|
+ }
|
|
370
|
+ }
|
|
371
|
+ }
|
|
372
|
+
|
|
373
|
+ public abstract class MethodDrawer
|
|
374
|
+ {
|
|
375
|
+ public MethodInfo methodInfo;
|
|
376
|
+ public MethodAttribute attribute;
|
|
377
|
+
|
|
378
|
+ public virtual void OnGUI(SerializedObject serializedObject)
|
|
379
|
+ {
|
|
380
|
+
|
|
381
|
+ }
|
|
382
|
+ }
|
|
383
|
+
|
|
384
|
+ public abstract class PropertyDrawer
|
|
385
|
+ {
|
|
386
|
+ public PropertyInfo propertyInfo;
|
|
387
|
+ public PropertyAttribute attribute;
|
|
388
|
+ public UObject target;
|
|
389
|
+ public EventButtonAttribute buttonAttribute;
|
|
390
|
+ public GetTransFormValueAttribute formValueAttribute;
|
|
391
|
+ public string Name;
|
|
392
|
+
|
|
393
|
+ public virtual void OnGUI(SerializedObject serializedObject)
|
|
394
|
+ {
|
|
395
|
+ target = serializedObject.targetObject;
|
|
396
|
+ Name = string.IsNullOrEmpty(attribute.Lable) ? propertyInfo.Name : attribute.Lable;
|
|
397
|
+ buttonAttribute = target?.GetType().GetCustomAttribute<EventButtonAttribute>();
|
|
398
|
+ formValueAttribute = target?.GetType().GetCustomAttribute<GetTransFormValueAttribute>();
|
|
399
|
+ using(new EditorGUILayout.HorizontalScope())
|
|
400
|
+ {
|
|
401
|
+ switch (attribute.DrawMode)
|
|
402
|
+ {
|
|
403
|
+ case DrawMode.EditModeAndRunTime:
|
|
404
|
+ OnDarw(serializedObject);
|
|
405
|
+ break;
|
|
406
|
+ case DrawMode.OnlyEditMode:
|
|
407
|
+ if (!EditorApplication.isPlaying)
|
|
408
|
+ OnDarwEditMode(serializedObject);
|
|
409
|
+ break;
|
|
410
|
+ case DrawMode.OnlyRuntime:
|
|
411
|
+ if (EditorApplication.isPlaying)
|
|
412
|
+ OnDarwRuntime(serializedObject);
|
|
413
|
+ break;
|
|
414
|
+ default:
|
|
415
|
+ DrawUI(serializedObject);
|
|
416
|
+ break;
|
|
417
|
+ }
|
|
418
|
+ if (attribute.IsEnableCopy)
|
|
419
|
+ {
|
|
420
|
+ if (GUILayout.Button("¸´ÖÆ",GUILayout.ExpandWidth(false)))
|
|
421
|
+ Copy(serializedObject);
|
|
422
|
+ }
|
|
423
|
+ if (attribute.IsEnadlePaste)
|
|
424
|
+ {
|
|
425
|
+ if (GUILayout.Button("Õ³Ìù", GUILayout.ExpandWidth(false)))
|
|
426
|
+ Paste(serializedObject);
|
|
427
|
+ }
|
|
428
|
+ if(buttonAttribute!=null)
|
|
429
|
+ {
|
|
430
|
+ if(GUILayout.Button(buttonAttribute.Lable, GUILayout.ExpandWidth(false)))
|
|
431
|
+ {
|
|
432
|
+ buttonAttribute.TypeValue.GetMethod(buttonAttribute.ActionName)?.Invoke(target,null);
|
|
433
|
+ }
|
|
434
|
+ }
|
|
435
|
+ if(formValueAttribute!=null)
|
|
436
|
+ {
|
|
437
|
+ if(GUILayout.Button(EditorGUIUtility.IconContent("Custom@2x").image, GUILayout.Width(30), GUILayout.Height(20)))
|
|
438
|
+ {
|
|
439
|
+ Vector3 value = (Vector3)propertyInfo.GetValue(target);
|
|
440
|
+ if(Selection.activeTransform)
|
|
441
|
+ switch (formValueAttribute.TranType)
|
|
442
|
+ {
|
|
443
|
+ case TranType.None:
|
|
444
|
+ break;
|
|
445
|
+ case TranType.Position:
|
|
446
|
+ value = Selection.activeTransform.position;
|
|
447
|
+ break;
|
|
448
|
+ case TranType.Rotation:
|
|
449
|
+ value = Selection.activeTransform.rotation.eulerAngles;
|
|
450
|
+ break;
|
|
451
|
+ case TranType.Scale:
|
|
452
|
+ value = Selection.activeTransform.localScale;
|
|
453
|
+ break;
|
|
454
|
+ default:
|
|
455
|
+ break;
|
|
456
|
+ }
|
|
457
|
+ propertyInfo.SetValue(target, value);
|
|
458
|
+ }
|
|
459
|
+ }
|
|
460
|
+ }
|
|
461
|
+ }
|
|
462
|
+
|
|
463
|
+ public virtual void Paste(SerializedObject serializedObject)
|
|
464
|
+ {
|
|
465
|
+ try
|
|
466
|
+ {
|
|
467
|
+ propertyInfo.SetValue(target, EditorGUIUtility.systemCopyBuffer);
|
|
468
|
+ MarkerChange();
|
|
469
|
+ }
|
|
470
|
+ catch
|
|
471
|
+ {
|
|
472
|
+
|
|
473
|
+ }
|
|
474
|
+ }
|
|
475
|
+
|
|
476
|
+ public virtual void Copy(SerializedObject serializedObject)
|
|
477
|
+ {
|
|
478
|
+ EditorGUIUtility.systemCopyBuffer = propertyInfo.GetValue(target).ToString();
|
|
479
|
+ }
|
|
480
|
+
|
|
481
|
+ public virtual void OnDarwRuntime(SerializedObject serializedObject)
|
|
482
|
+ {
|
|
483
|
+ DrawUI(serializedObject);
|
|
484
|
+ }
|
|
485
|
+
|
|
486
|
+ public virtual void OnDarwEditMode(SerializedObject serializedObject)
|
|
487
|
+ {
|
|
488
|
+ DrawUI(serializedObject);
|
|
489
|
+ }
|
|
490
|
+
|
|
491
|
+ public virtual void OnDarw(SerializedObject serializedObject)
|
|
492
|
+ {
|
|
493
|
+ DrawUI(serializedObject);
|
|
494
|
+ }
|
|
495
|
+
|
|
496
|
+ public void MarkerChange()
|
|
497
|
+ {
|
|
498
|
+ if (target == null) return;
|
|
499
|
+ EditorUtility.SetDirty(target);
|
|
500
|
+ if (EditorApplication.isPlaying) return;
|
|
501
|
+
|
|
502
|
+ Component component = target as Component;
|
|
503
|
+ if (component != null && component.gameObject.scene != null)
|
|
504
|
+ {
|
|
505
|
+ EditorSceneManager.MarkSceneDirty(component.gameObject.scene);
|
|
506
|
+ }
|
|
507
|
+ }
|
|
508
|
+
|
|
509
|
+ public abstract void DrawUI(SerializedObject serializedObject);
|
|
510
|
+ }
|
|
511
|
+
|
|
512
|
+ [CustomPropertyDrawer(typeof(LabelAttribute),true)]
|
|
513
|
+ public class LabelAttributeDrawer:BaseAttributeDrawer
|
|
514
|
+ {
|
|
515
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
516
|
+ {
|
|
517
|
+ LabelAttribute _attribute = (LabelAttribute)attribute;
|
|
518
|
+ label.text = _attribute.Text;
|
|
519
|
+ EditorGUI.PropertyField(position, property, label);
|
|
520
|
+ }
|
|
521
|
+ }
|
|
522
|
+
|
|
523
|
+ [CustomPropertyDrawer(typeof(EventButtonAttribute), true)]
|
|
524
|
+ public class EventButtonAttributeDrawer : BaseAttributeDrawer
|
|
525
|
+ {
|
|
526
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
527
|
+ {
|
|
528
|
+ EventButtonAttribute _attribute = (EventButtonAttribute)attribute;
|
|
529
|
+ float width = position.width - 33;
|
|
530
|
+ width += 23;
|
|
531
|
+ if (GUI.Button(new Rect(width,position.y,30,position.height),_attribute.Lable))
|
|
532
|
+ {
|
|
533
|
+ _attribute.TypeValue.GetMethod(_attribute.ActionName).Invoke(target, null);
|
|
534
|
+ }
|
|
535
|
+ EditorGUI.PropertyField(new Rect(position.x,position.y,width-23,position.height), property, label);
|
|
536
|
+ }
|
|
537
|
+ }
|
|
538
|
+
|
|
539
|
+ [CustomPropertyDrawer(typeof(DropdownAttribute),true)]
|
|
540
|
+ public class DropdownAttributeDrawer : BaseAttributeDrawer
|
|
541
|
+ {
|
|
542
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
543
|
+ {
|
|
544
|
+ object value = fieldInfo.GetValue(property.serializedObject.targetObject);
|
|
545
|
+ DropdownAttribute dropdown = attribute as DropdownAttribute;
|
|
546
|
+ int selectIndex = dropdown.Values.IndexOf(value);
|
|
547
|
+ if (selectIndex < 0)
|
|
548
|
+ {
|
|
549
|
+ selectIndex = 0;
|
|
550
|
+ fieldInfo.SetValue(property.serializedObject.targetObject, dropdown.Values[selectIndex]);
|
|
551
|
+ MarkerChange();
|
|
552
|
+ }
|
|
553
|
+
|
|
554
|
+ EditorGUI.BeginChangeCheck();
|
|
555
|
+ int newIndex = EditorGUI.Popup(position,label.text, selectIndex, dropdown.DisplayOptions.ToArray());
|
|
556
|
+ if (EditorGUI.EndChangeCheck())
|
|
557
|
+ {
|
|
558
|
+ Undo.RecordObject(target, "Dropdown");
|
|
559
|
+ fieldInfo.SetValue(target, dropdown.Values[newIndex]);
|
|
560
|
+ MarkerChange();
|
|
561
|
+ }
|
|
562
|
+ }
|
|
563
|
+ }
|
|
564
|
+
|
|
565
|
+ [CustomPropertyDrawer(typeof(SceneAttribute))]
|
|
566
|
+ public class SceneAttributeDrawer : BaseAttributeDrawer
|
|
567
|
+ {
|
|
568
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
569
|
+ {
|
|
570
|
+ object value = fieldInfo.GetValue(target);
|
|
571
|
+ EditorGUI.BeginChangeCheck();
|
|
572
|
+ SceneAsset scene = EditorGUI.ObjectField(position,label, AssetDatabase.LoadAssetAtPath<SceneAsset>((string)value), typeof(SceneAsset), false) as SceneAsset;
|
|
573
|
+
|
|
574
|
+ if (EditorGUI.EndChangeCheck())
|
|
575
|
+ {
|
|
576
|
+ Undo.RecordObject(target, "Scene");
|
|
577
|
+ fieldInfo.SetValue(target, AssetDatabase.GetAssetPath(scene));
|
|
578
|
+ MarkerChange();
|
|
579
|
+ }
|
|
580
|
+ }
|
|
581
|
+ }
|
|
582
|
+
|
|
583
|
+ [CustomPropertyDrawer(typeof(RelevancyShowAttribute))]
|
|
584
|
+ public class RelevancyShowAttributeDrawer : BaseAttributeDrawer
|
|
585
|
+ {
|
|
586
|
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Default | BindingFlags.Instance;
|
|
587
|
+
|
|
588
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
589
|
+ {
|
|
590
|
+ EditorGUI.PropertyField(position, property, label);
|
|
591
|
+ }
|
|
592
|
+
|
|
593
|
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
594
|
+ {
|
|
595
|
+ RelevancyShowAttribute _attribute = attribute as RelevancyShowAttribute;
|
|
596
|
+ MemberInfo[] member = property.serializedObject.targetObject.GetType().GetMember(_attribute.FieldName, flags);
|
|
597
|
+ if (member != null && member.Length > 0)
|
|
598
|
+ {
|
|
599
|
+ if (member[0].MemberType == MemberTypes.Field)
|
|
600
|
+ _attribute.IsShow = (member[0] as FieldInfo).GetValue(property.serializedObject.targetObject).Equals(_attribute.ShowValue);
|
|
601
|
+ else if (member[0].MemberType == MemberTypes.Property)
|
|
602
|
+ _attribute.IsShow = (member[0] as PropertyInfo).GetValue(property.serializedObject.targetObject).Equals(_attribute.ShowValue);
|
|
603
|
+ else if (member[0].MemberType == MemberTypes.Method)
|
|
604
|
+ _attribute.IsShow = (member[0] as MethodInfo).Invoke(property.serializedObject.targetObject, null).Equals(_attribute.ShowValue);
|
|
605
|
+ }
|
|
606
|
+ return base.GetPropertyHeight(property, label);
|
|
607
|
+ }
|
|
608
|
+ }
|
|
609
|
+
|
|
610
|
+ [CustomPropertyDrawer(typeof(OnlyReadAttribute))]
|
|
611
|
+ public class OnlyReadAttributeDrawer : BaseAttributeDrawer
|
|
612
|
+ {
|
|
613
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
614
|
+ {
|
|
615
|
+ GUI.enabled = false;
|
|
616
|
+ EditorGUI.PropertyField(position, property, label);
|
|
617
|
+ GUI.enabled = true;
|
|
618
|
+ }
|
|
619
|
+ }
|
|
620
|
+
|
|
621
|
+ [CustomPropertyDrawer(typeof(BegingFoldAttribute))]
|
|
622
|
+ public class BegingFoldAttributeDrawer : BaseAttributeDrawer
|
|
623
|
+ {
|
|
624
|
+ int count = 0;
|
|
625
|
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|
626
|
+
|
|
627
|
+ public override void OnDarwBefore(Rect position, SerializedProperty property, GUIContent label)
|
|
628
|
+ {
|
|
629
|
+ BegingFoldAttribute _attribute = attribute as BegingFoldAttribute;
|
|
630
|
+ property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, _attribute.Label);
|
|
631
|
+ }
|
|
632
|
+
|
|
633
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
634
|
+ {
|
|
635
|
+ position.y += 23;
|
|
636
|
+ position.height = 20;
|
|
637
|
+ EditorGUI.PropertyField(position, property, label);
|
|
638
|
+ }
|
|
639
|
+
|
|
640
|
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
|
641
|
+ {
|
|
642
|
+ using (SerializedProperty iterator = property.serializedObject.GetIterator())
|
|
643
|
+ {
|
|
644
|
+ HashSet<string> fieldPaths = new HashSet<string>();
|
|
645
|
+ bool flags1 = false;
|
|
646
|
+ while (iterator.NextVisible(true))
|
|
647
|
+ {
|
|
648
|
+ SerializedProperty _property = property.serializedObject.FindProperty(iterator.name);
|
|
649
|
+ if (!flags1)
|
|
650
|
+ flags1 = _property.propertyPath == property.propertyPath;
|
|
651
|
+ if (_property != null && !fieldPaths.Contains(_property.propertyPath)&&flags1)
|
|
652
|
+ {
|
|
653
|
+ fieldPaths.Add(_property.propertyPath);
|
|
654
|
+ FieldInfo fieldInfo = _property.serializedObject.targetObject.GetType().GetField(_property.name, flags);
|
|
655
|
+ InspectorAttribute _attribute = fieldInfo.GetCustomAttribute<InspectorAttribute>();
|
|
656
|
+ if(_attribute!=null)
|
|
657
|
+ {
|
|
658
|
+ if (fieldInfo.GetCustomAttribute<BegingFoldAttribute>() != null)
|
|
659
|
+ {
|
|
660
|
+ count++;
|
|
661
|
+ }
|
|
662
|
+ if(fieldInfo.GetCustomAttribute<EndFoldAttribute>() != null)
|
|
663
|
+ {
|
|
664
|
+ count--;
|
|
665
|
+ if (count == 0)
|
|
666
|
+ break;
|
|
667
|
+ }
|
|
668
|
+ }
|
|
669
|
+ _property.isExpanded = property.isExpanded;
|
|
670
|
+ }
|
|
671
|
+ }
|
|
672
|
+ }
|
|
673
|
+
|
|
674
|
+ return base.GetPropertyHeight(property, label)+23;
|
|
675
|
+ }
|
|
676
|
+ }
|
|
677
|
+
|
|
678
|
+ [CustomPropertyDrawer(typeof(GetTransFormValueAttribute))]
|
|
679
|
+ public class GetTransFormValueAttributeDrawer : BaseAttributeDrawer
|
|
680
|
+ {
|
|
681
|
+ public override void DrawUI(Rect position, SerializedProperty property, GUIContent label)
|
|
682
|
+ {
|
|
683
|
+ GetTransFormValueAttribute _attribute = (GetTransFormValueAttribute)attribute;
|
|
684
|
+ float width = position.width - 33;
|
|
685
|
+ width += 23;
|
|
686
|
+ if (GUI.Button(new Rect(width, position.y, 30, position.height), EditorGUIUtility.IconContent("Custom@2x").image))
|
|
687
|
+ {
|
|
688
|
+ Vector3 value = property.vector3Value;
|
|
689
|
+ if (Selection.activeTransform)
|
|
690
|
+ switch (_attribute.TranType)
|
|
691
|
+ {
|
|
692
|
+ case TranType.None:
|
|
693
|
+ break;
|
|
694
|
+ case TranType.Position:
|
|
695
|
+ value = Selection.activeTransform.position;
|
|
696
|
+ break;
|
|
697
|
+ case TranType.Rotation:
|
|
698
|
+ value = Selection.activeTransform.rotation.eulerAngles;
|
|
699
|
+ break;
|
|
700
|
+ case TranType.Scale:
|
|
701
|
+ value = Selection.activeTransform.localScale;
|
|
702
|
+ break;
|
|
703
|
+ default:
|
|
704
|
+ break;
|
|
705
|
+ }
|
|
706
|
+ property.vector3Value = value;
|
|
707
|
+ }
|
|
708
|
+ EditorGUI.PropertyField(new Rect(position.x, position.y, width-23, position.height), property, label);
|
|
709
|
+ }
|
|
710
|
+ }
|
|
711
|
+
|
|
712
|
+ [TCustomPropertyDrawer(typeof(PropertyAttribute))]
|
|
713
|
+ public class PropertyAttributeDrawer : PropertyDrawer
|
|
714
|
+ {
|
|
715
|
+ public override void DrawUI(SerializedObject serializedObject)
|
|
716
|
+ {
|
|
717
|
+ if (propertyInfo.CanWrite)
|
|
718
|
+ {
|
|
719
|
+ CanWritePainting();
|
|
720
|
+ }
|
|
721
|
+ else
|
|
722
|
+ {
|
|
723
|
+ ReadOnlyPainting();
|
|
724
|
+ }
|
|
725
|
+ }
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+ private void CanWritePainting()
|
|
729
|
+ {
|
|
730
|
+ EditorGUI.BeginChangeCheck();
|
|
731
|
+ object value = propertyInfo.GetValue(target);
|
|
732
|
+ object newValue = value;
|
|
733
|
+ if (propertyInfo.PropertyType.IsEnum)
|
|
734
|
+ {
|
|
735
|
+ Enum realValue = EditorGUILayout.EnumPopup(Name, (Enum)value);
|
|
736
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
737
|
+ }
|
|
738
|
+ else if (propertyInfo.PropertyType == typeof(string))
|
|
739
|
+ {
|
|
740
|
+ string realValue = EditorGUILayout.TextField(Name, (string)value);
|
|
741
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
742
|
+ }
|
|
743
|
+ else if (propertyInfo.PropertyType == typeof(int))
|
|
744
|
+ {
|
|
745
|
+ int realValue = EditorGUILayout.IntField(Name, (int)value);
|
|
746
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
747
|
+ }
|
|
748
|
+ else if (propertyInfo.PropertyType == typeof(float))
|
|
749
|
+ {
|
|
750
|
+ float realValue = EditorGUILayout.FloatField(Name, (float)value);
|
|
751
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
752
|
+ }
|
|
753
|
+ else if (propertyInfo.PropertyType == typeof(bool))
|
|
754
|
+ {
|
|
755
|
+ bool realValue = EditorGUILayout.Toggle(Name, (bool)value);
|
|
756
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
757
|
+ }
|
|
758
|
+ else if (propertyInfo.PropertyType == typeof(Vector2))
|
|
759
|
+ {
|
|
760
|
+ Vector2 realValue = EditorGUILayout.Vector2Field(Name, (Vector2)value);
|
|
761
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
762
|
+ }
|
|
763
|
+ else if (propertyInfo.PropertyType == typeof(Vector3))
|
|
764
|
+ {
|
|
765
|
+ Vector3 realValue = EditorGUILayout.Vector3Field(Name, (Vector3)value);
|
|
766
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
767
|
+ }
|
|
768
|
+ else if (propertyInfo.PropertyType == typeof(Color))
|
|
769
|
+ {
|
|
770
|
+ Color realValue = EditorGUILayout.ColorField(Name, (Color)value);
|
|
771
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
772
|
+ }
|
|
773
|
+ else if (propertyInfo.PropertyType.IsSubclassOf(typeof(UObject)))
|
|
774
|
+ {
|
|
775
|
+ UObject realValue = EditorGUILayout.ObjectField(Name, value as UObject, propertyInfo.PropertyType, true);
|
|
776
|
+ if (EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
777
|
+ }
|
|
778
|
+ else
|
|
779
|
+ {
|
|
780
|
+ string realValue = EditorGUILayout.TextField(Name, value != null ? value.ToString() : "null");
|
|
781
|
+ if(EditorGUI.EndChangeCheck()) newValue = realValue;
|
|
782
|
+ }
|
|
783
|
+
|
|
784
|
+ if (value != newValue)
|
|
785
|
+ {
|
|
786
|
+ Undo.RecordObject(target, "propertyInfo Changed");
|
|
787
|
+ propertyInfo.SetValue(target, newValue);
|
|
788
|
+ MarkerChange();
|
|
789
|
+ }
|
|
790
|
+ }
|
|
791
|
+
|
|
792
|
+ private void ReadOnlyPainting()
|
|
793
|
+ {
|
|
794
|
+ GUI.enabled = false;
|
|
795
|
+
|
|
796
|
+ object value = propertyInfo.GetValue(target);
|
|
797
|
+ if (propertyInfo.PropertyType.IsEnum)
|
|
798
|
+ {
|
|
799
|
+ EditorGUILayout.EnumPopup(Name, (Enum)value);
|
|
800
|
+ }
|
|
801
|
+ else if (propertyInfo.PropertyType == typeof(string))
|
|
802
|
+ {
|
|
803
|
+ EditorGUILayout.TextField(Name, (string)value);
|
|
804
|
+ }
|
|
805
|
+ else if (propertyInfo.PropertyType == typeof(int))
|
|
806
|
+ {
|
|
807
|
+ EditorGUILayout.IntField(Name, (int)value);
|
|
808
|
+ }
|
|
809
|
+ else if (propertyInfo.PropertyType == typeof(float))
|
|
810
|
+ {
|
|
811
|
+ EditorGUILayout.FloatField(Name, (float)value);
|
|
812
|
+ }
|
|
813
|
+ else if (propertyInfo.PropertyType == typeof(bool))
|
|
814
|
+ {
|
|
815
|
+ EditorGUILayout.Toggle(Name, (bool)value);
|
|
816
|
+ }
|
|
817
|
+ else if (propertyInfo.PropertyType == typeof(Vector2))
|
|
818
|
+ {
|
|
819
|
+ EditorGUILayout.Vector2Field(Name, (Vector2)value);
|
|
820
|
+ }
|
|
821
|
+ else if (propertyInfo.PropertyType == typeof(Vector3))
|
|
822
|
+ {
|
|
823
|
+ EditorGUILayout.Vector3Field(Name, (Vector3)value);
|
|
824
|
+ }
|
|
825
|
+ else if (propertyInfo.PropertyType == typeof(Color))
|
|
826
|
+ {
|
|
827
|
+ EditorGUILayout.ColorField(Name, (Color)value);
|
|
828
|
+ }
|
|
829
|
+ else if (propertyInfo.PropertyType.IsSubclassOf(typeof(UObject)))
|
|
830
|
+ {
|
|
831
|
+ EditorGUILayout.ObjectField(Name, value as UObject, propertyInfo.PropertyType, false);
|
|
832
|
+ }
|
|
833
|
+ else
|
|
834
|
+ {
|
|
835
|
+ EditorGUILayout.TextField(Name, value != null ? value.ToString() : "null");
|
|
836
|
+ }
|
|
837
|
+ GUI.enabled = true;
|
|
838
|
+ }
|
|
839
|
+ }
|
|
840
|
+
|
|
841
|
+ [CustomMethodDrawer(typeof(ButtonAttribute))]
|
|
842
|
+ public class ButtonAttributeDrawer : MethodDrawer
|
|
843
|
+ {
|
|
844
|
+ BindingFlags flags = BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Default;
|
|
845
|
+ public bool IsActive = true;
|
|
846
|
+ public string Name;
|
|
847
|
+
|
|
848
|
+ public override void OnGUI(SerializedObject serializedObject)
|
|
849
|
+ {
|
|
850
|
+ ButtonAttribute _attribute = attribute as ButtonAttribute;
|
|
851
|
+ Name = string.IsNullOrEmpty(_attribute.Name) ? methodInfo.Name : _attribute.Name;
|
|
852
|
+ if (!string.IsNullOrEmpty(_attribute.CriteriaName))
|
|
853
|
+ {
|
|
854
|
+ MemberInfo[] member = serializedObject.targetObject.GetType().GetMember(_attribute.CriteriaName, flags);
|
|
855
|
+
|
|
856
|
+ if (member != null && member.Length > 0)
|
|
857
|
+ {
|
|
858
|
+ if (member[0].MemberType == MemberTypes.Field)
|
|
859
|
+ IsActive = (bool)(member[0] as FieldInfo).GetValue(serializedObject.targetObject);
|
|
860
|
+ else if (member[0].MemberType == MemberTypes.Property)
|
|
861
|
+ IsActive = (bool)(member[0] as PropertyInfo).GetValue(serializedObject.targetObject);
|
|
862
|
+ else if (member[0].MemberType == MemberTypes.Method)
|
|
863
|
+ IsActive = (bool)(member[0] as MethodInfo).Invoke(serializedObject.targetObject, null);
|
|
864
|
+ }
|
|
865
|
+
|
|
866
|
+ GUI.enabled = IsActive == _attribute.CriteriaVaule;
|
|
867
|
+ }
|
|
868
|
+ if (GUILayout.Button(Name))
|
|
869
|
+ {
|
|
870
|
+ if (methodInfo.IsStatic)
|
|
871
|
+ methodInfo.Invoke(null, _attribute.Parameter);
|
|
872
|
+ else
|
|
873
|
+ methodInfo.Invoke(serializedObject.targetObject, _attribute.Parameter);
|
|
874
|
+ }
|
|
875
|
+ GUI.enabled = true;
|
|
876
|
+ }
|
|
877
|
+ }
|
|
878
|
+
|
|
879
|
+}
|