Skip to content

Commit 675078a

Browse files
committed
Minor fixes
- Prettify Method display - Display property names as tooltips.
1 parent 4ba4da9 commit 675078a

File tree

3 files changed

+48
-47
lines changed

3 files changed

+48
-47
lines changed

Assets/Script Tester/Editor/ComponentMethodDrawer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@ string GetMethodNameFormatted(ComponentMethod m, int i) {
256256
name = "[Constructor]";
257257
} else {
258258
method = m.method;
259-
name = Helper.GetMemberName(method as MemberInfo);
259+
name = Helper.GetMemberName(method as MemberInfo).replace('_', ' ');
260260
}
261-
var result = string.Format("{0} {1} ({2})", i + 1, name, Helper.JoinStringList(null, method.GetParameters().Select(x => x.ParameterType.Name), ", "));
262-
result = result.Replace (" _", "_");
261+
var result = string.Format("{0:000} {1} ({2})", i + 1, name, Helper.JoinStringList(null, method.GetParameters().Select(x => x.ParameterType.Name), ", "));
263262
return result;
264263
}
265264

Assets/Script Tester/Editor/Helpers.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,24 @@ internal static Quaternion QuaternionField(Rect position, string label, Quaterni
191191
return new Quaternion(cValue.x, cValue.y, cValue.z, cValue.w);
192192
}
193193

194-
internal static int EnumField(Rect position, string label, Type type, int value) {
195-
string[] itemNames;
194+
internal static int EnumField(Rect position, GUIContent label, Type type, int value) {
195+
GUIContent[] itemNames;
196196
int[] itemValues;
197197
int val = EnumFieldPreProcess(type, value, out itemNames, out itemValues);
198198
int newVal = EditorGUI.Popup(position, label, val, itemNames);
199199
return EnumFieldPostProcess(itemValues, newVal);
200200
}
201201

202-
internal static int EnumField(string label, Type type, int value, params GUILayoutOption[] options) {
203-
string[] itemNames;
202+
internal static int EnumField(GUIContent label, Type type, int value, params GUILayoutOption[] options) {
203+
GUIContent[] itemNames;
204204
int[] itemValues;
205205
int val = EnumFieldPreProcess(type, value, out itemNames, out itemValues);
206206
int newVal = EditorGUILayout.Popup(label, val, itemNames, options);
207207
return EnumFieldPostProcess(itemValues, newVal);
208208
}
209209

210-
static int EnumFieldPreProcess(Type type, int val, out string[] itemNames, out int[] itemValues) {
211-
itemNames = Enum.GetNames(type);
210+
static int EnumFieldPreProcess(Type type, int val, out GUIContent[] itemNames, out int[] itemValues) {
211+
itemNames = Enum.GetNames(type).Select(x => new GUIContent(x)).ToArray();
212212
itemValues = Enum.GetValues(type) as int[];
213213
for(int i = 0; i < itemValues.Length; i++)
214214
if(val == itemValues[i])
@@ -275,7 +275,7 @@ static int MaskedEnumFieldPostProcess(int[] itemValues, int val, int maskVal, in
275275
return val;
276276
}
277277

278-
internal static string StringField(string label, string value, bool readOnly, params GUILayoutOption[] options) {
278+
internal static string StringField(GUIContent label, string value, bool readOnly, params GUILayoutOption[] options) {
279279
int length = value == null ? 0 : value.Length;
280280
if(length > 5000) {
281281
EditorGUILayout.BeginHorizontal();
@@ -315,7 +315,7 @@ internal static string StringField(string label, string value, bool readOnly, pa
315315
return value;
316316
}
317317

318-
internal static string StringField(Rect position, string label, string value, bool readOnly) {
318+
internal static string StringField(Rect position, GUIContent label, string value, bool readOnly) {
319319
if(readOnly) {
320320
EditorGUI.SelectableLabel(position, value);
321321
} else {
@@ -329,7 +329,7 @@ internal static string StringField(Rect position, string label, string value, bo
329329
return value;
330330
}
331331

332-
internal static UnityObject ObjectField(string label, UnityObject value, Type objectType, bool allowScreenObjs, bool readOnly, params GUILayoutOption[] options) {
332+
internal static UnityObject ObjectField(GUIContent label, UnityObject value, Type objectType, bool allowScreenObjs, bool readOnly, params GUILayoutOption[] options) {
333333
if(!readOnly)
334334
return EditorGUILayout.ObjectField(label, value, objectType, allowScreenObjs, options);
335335
EditorGUILayout.BeginHorizontal();
@@ -342,10 +342,10 @@ internal static UnityObject ObjectField(string label, UnityObject value, Type ob
342342
return value;
343343
}
344344

345-
internal static UnityObject ObjectField(Rect position, string label, UnityObject value, Type objectType, bool allowScreenObjs, bool readOnly) {
345+
internal static UnityObject ObjectField(Rect position, GUIContent label, UnityObject value, Type objectType, bool allowScreenObjs, bool readOnly) {
346346
if(!readOnly)
347347
return EditorGUI.ObjectField(position, label, value, objectType, allowScreenObjs);
348-
EditorGUI.PrefixLabel(ScaleRect(position, widthScale: 0.5F), new GUIContent(label));
348+
EditorGUI.PrefixLabel(ScaleRect(position, widthScale: 0.5F), label);
349349
if(GUI.Button(ScaleRect(position, 0.5F, widthScale: 0.5F), EditorGUIUtility.ObjectContent(value, objectType), EditorStyles.objectField))
350350
ClickObject(value);
351351
return value;

Assets/Script Tester/Editor/MethodPropertyDrawer.cs

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace ScriptTester {
1212
class MethodPropertyDrawer:IReflectorDrawer {
1313
public readonly string name;
14+
readonly GUIContent nameContent;
1415
MemberInfo memberInfo;
1516
public Type requiredType;
1617
readonly List<PropertyType> castableTypes;
@@ -198,6 +199,7 @@ public Exception GetException {
198199
public MethodPropertyDrawer(Type type, string name, object defaultValue, bool allowPrivate, bool allowObsolete) {
199200
this.requiredType = type;
200201
this.name = name;
202+
this.nameContent = new GUIContent (name, name);
201203
this.rawValue = defaultValue;
202204
this.castableTypes = new List<PropertyType>();
203205
this.fields = new List<ComponentFields>();
@@ -424,62 +426,62 @@ void DrawDirectField(bool readOnly, Rect? rect) {
424426
switch(currentType) {
425427
case PropertyType.Bool:
426428
if(rect.HasValue)
427-
value = EditorGUI.Toggle(rect.Value, name, (bool)(value ?? false));
429+
value = EditorGUI.Toggle(rect.Value, nameContent, (bool)(value ?? false));
428430
else
429-
value = EditorGUILayout.Toggle(name, (bool)(value ?? false));
431+
value = EditorGUILayout.Toggle(nameContent, (bool)(value ?? false));
430432
break;
431433
case PropertyType.Enum:
432434
if(masked || readOnly) {
433435
if(rect.HasValue)
434-
value = Helper.MaskedEnumField(rect.Value, name, requiredType, (int)(value ?? 0));
436+
value = Helper.MaskedEnumField(rect.Value, nameContent, requiredType, (int)(value ?? 0));
435437
else
436-
value = Helper.MaskedEnumField(name, requiredType, (int)(value ?? 0));
438+
value = Helper.MaskedEnumField(nameContent, requiredType, (int)(value ?? 0));
437439
break;
438440
}
439441
if(rect.HasValue)
440-
value = Helper.EnumField(rect.Value, name, requiredType, (int)(value ?? 0));
442+
value = Helper.EnumField(rect.Value, nameContent, requiredType, (int)(value ?? 0));
441443
else
442-
value = Helper.EnumField(name, requiredType, (int)(value ?? 0));
444+
value = Helper.EnumField(nameContent, requiredType, (int)(value ?? 0));
443445
break;
444446
case PropertyType.Long:
445447
#if UNITY_5
446448
if(rect.HasValue)
447-
value = EditorGUI.LongField(rect.Value, name, (long)(value ?? 0L));
449+
value = EditorGUI.LongField(rect.Value, nameContent, (long)(value ?? 0L));
448450
else
449-
value = EditorGUILayout.LongField(name, (long)(value ?? 0L));
451+
value = EditorGUILayout.LongField(nameContent, (long)(value ?? 0L));
450452
break;
451453
#endif
452454
case PropertyType.Integer:
453455
if(rect.HasValue)
454-
value = EditorGUI.IntField(rect.Value, name, (int)(value ?? 0));
456+
value = EditorGUI.IntField(rect.Value, nameContent, (int)(value ?? 0));
455457
else
456-
value = EditorGUILayout.IntField(name, (int)(value ?? 0));
458+
value = EditorGUILayout.IntField(nameContent, (int)(value ?? 0));
457459
break;
458460
case PropertyType.Double:
459461
#if UNITY_5
460462
if(rect.HasValue)
461-
value = EditorGUI.DoubleField(rect.Value, name, (double)(value ?? 0));
463+
value = EditorGUI.DoubleField(rect.Value, nameContent, (double)(value ?? 0));
462464
else
463-
value = EditorGUILayout.DoubleField(name, (double)(value ?? 0));
465+
value = EditorGUILayout.DoubleField(nameContent, (double)(value ?? 0));
464466
break;
465467
#endif
466468
case PropertyType.Single:
467469
if(rect.HasValue)
468-
value = EditorGUI.FloatField(rect.Value, name, (float)(value ?? 0F));
470+
value = EditorGUI.FloatField(rect.Value, nameContent, (float)(value ?? 0F));
469471
else
470-
value = EditorGUILayout.FloatField(name, (float)(value ?? 0F));
472+
value = EditorGUILayout.FloatField(nameContent, (float)(value ?? 0F));
471473
break;
472474
case PropertyType.Vector2:
473475
if(rect.HasValue)
474-
value = EditorGUI.Vector2Field(rect.Value, name, (Vector2)(value ?? Vector2.zero));
476+
value = EditorGUI.Vector2Field(rect.Value, nameContent, (Vector2)(value ?? Vector2.zero));
475477
else
476-
value = EditorGUILayout.Vector2Field(name, (Vector2)(value ?? Vector2.zero));
478+
value = EditorGUILayout.Vector2Field(nameContent, (Vector2)(value ?? Vector2.zero));
477479
break;
478480
case PropertyType.Vector3:
479481
if(rect.HasValue)
480-
value = EditorGUI.Vector3Field(rect.Value, name, (Vector3)(value ?? Vector3.zero));
482+
value = EditorGUI.Vector3Field(rect.Value, nameContent, (Vector3)(value ?? Vector3.zero));
481483
else
482-
value = EditorGUILayout.Vector3Field(name, (Vector3)(value ?? Vector3.zero));
484+
value = EditorGUILayout.Vector3Field(nameContent, (Vector3)(value ?? Vector3.zero));
483485
break;
484486
case PropertyType.Vector4:
485487
if(rect.HasValue)
@@ -495,58 +497,58 @@ void DrawDirectField(bool readOnly, Rect? rect) {
495497
break;
496498
case PropertyType.Color:
497499
if(rect.HasValue)
498-
value = EditorGUI.ColorField(rect.Value, name, (Color)(value ?? Color.white));
500+
value = EditorGUI.ColorField(rect.Value, nameContent, (Color)(value ?? Color.white));
499501
else
500-
value = EditorGUILayout.ColorField(name, (Color)(value ?? Color.white));
502+
value = EditorGUILayout.ColorField(nameContent, (Color)(value ?? Color.white));
501503
break;
502504
case PropertyType.Rect:
503505
if(rect.HasValue)
504-
value = EditorGUI.RectField(rect.Value, name, (Rect)(value ?? default(Rect)));
506+
value = EditorGUI.RectField(rect.Value, nameContent, (Rect)(value ?? default(Rect)));
505507
else
506-
value = EditorGUILayout.RectField(name, (Rect)(value ?? default(Rect)));
508+
value = EditorGUILayout.RectField(nameContent, (Rect)(value ?? default(Rect)));
507509
break;
508510
case PropertyType.Bounds:
509511
if(rect.HasValue)
510-
value = EditorGUI.BoundsField(rect.Value, new GUIContent(name), (Bounds)(value ?? default(Bounds)));
512+
value = EditorGUI.BoundsField(rect.Value, nameContent, (Bounds)(value ?? default(Bounds)));
511513
else
512-
value = EditorGUILayout.BoundsField(name, (Bounds)(value ?? default(Bounds)));
514+
value = EditorGUILayout.BoundsField(nameContent, (Bounds)(value ?? default(Bounds)));
513515
break;
514516
case PropertyType.Curve:
515517
if(rect.HasValue)
516-
value = EditorGUI.CurveField(rect.Value, name, (AnimationCurve)(value ?? new AnimationCurve()));
518+
value = EditorGUI.CurveField(rect.Value, nameContent, (AnimationCurve)(value ?? new AnimationCurve()));
517519
else
518-
value = EditorGUILayout.CurveField(name, (AnimationCurve)(value ?? new AnimationCurve()));
520+
value = EditorGUILayout.CurveField(nameContent, (AnimationCurve)(value ?? new AnimationCurve()));
519521
break;
520522
case PropertyType.Object:
521523
if(rect.HasValue)
522-
value = Helper.ObjectField(rect.Value, name, (UnityObject)value, requiredType, true, readOnly);
524+
value = Helper.ObjectField(rect.Value, nameContent, (UnityObject)value, requiredType, true, readOnly);
523525
else
524-
value = Helper.ObjectField(name, (UnityObject)value, requiredType, true, readOnly);
526+
value = Helper.ObjectField(nameContent, (UnityObject)value, requiredType, true, readOnly);
525527
break;
526528
case PropertyType.Array:
527529
if(rect.HasValue) {
528530
arrayHandler.DoList(rect.Value);
529531
break;
530532
}
531533
EditorGUILayout.BeginVertical();
532-
if(arrayShown = EditorGUILayout.Foldout(arrayShown, name))
534+
if(arrayShown = EditorGUILayout.Foldout(arrayShown, nameContent))
533535
arrayHandler.DoLayoutList();
534536
EditorGUILayout.EndVertical();
535537
break;
536538
case PropertyType.String:
537539
if(rect.HasValue)
538-
value = Helper.StringField(rect.Value, name, (string)value, readOnly);
540+
value = Helper.StringField(rect.Value, nameContent, (string)value, readOnly);
539541
else
540-
value = Helper.StringField(name, (string)value, readOnly);
542+
value = Helper.StringField(nameContent, (string)value, readOnly);
541543
break;
542544
default:
543545
var stringValue = value != null ? value.ToString() : "Null";
544546
if(rect.HasValue) {
545-
Helper.StringField(rect.Value, name, stringValue, true);
547+
Helper.StringField(rect.Value, nameContent, stringValue, true);
546548
DrawUnknownField(readOnly, value);
547549
} else {
548550
EditorGUILayout.BeginVertical();
549-
Helper.StringField(name, stringValue, true);
551+
Helper.StringField(nameContent, stringValue, true);
550552
DrawUnknownField(readOnly, value);
551553
EditorGUILayout.EndVertical();
552554
}

0 commit comments

Comments
 (0)