@@ -11,55 +11,72 @@ namespace Explorer
11
11
{
12
12
public class CacheOther : CacheObjectBase
13
13
{
14
+ public string ButtonLabel => m_btnLabel ?? GetButtonLabel ( ) ;
15
+ private string m_btnLabel ;
16
+
17
+ public MethodInfo ToStringMethod => m_toStringMethod ?? GetToStringMethod ( ) ;
14
18
private MethodInfo m_toStringMethod ;
15
19
16
- public MethodInfo ToStringMethod
20
+ public override void DrawValue ( Rect window , float width )
17
21
{
18
- get
22
+ GUI . skin . button . alignment = TextAnchor . MiddleLeft ;
23
+ if ( GUILayout . Button ( ButtonLabel , new GUILayoutOption [ ] { GUILayout . Width ( width - 15 ) } ) )
19
24
{
20
- if ( m_toStringMethod == null )
21
- {
22
- try
23
- {
24
- m_toStringMethod = ReflectionHelpers . GetActualType ( Value ) . GetMethod ( "ToString" , new Type [ 0 ] )
25
- ?? typeof ( object ) . GetMethod ( "ToString" , new Type [ 0 ] ) ;
26
-
27
- // test invoke
28
- m_toStringMethod . Invoke ( Value , null ) ;
29
- }
30
- catch
31
- {
32
- m_toStringMethod = typeof ( object ) . GetMethod ( "ToString" , new Type [ 0 ] ) ;
33
- }
34
- }
35
- return m_toStringMethod ;
25
+ WindowManager . InspectObject ( Value , out bool _ ) ;
36
26
}
27
+ GUI . skin . button . alignment = TextAnchor . MiddleCenter ;
37
28
}
38
29
39
- public override void DrawValue ( Rect window , float width )
30
+ private MethodInfo GetToStringMethod ( )
40
31
{
41
- string label = ( string ) ToStringMethod ? . Invoke ( Value , null ) ?? Value . ToString ( ) ;
42
-
43
- if ( ! label . Contains ( ValueTypeName ) )
32
+ try
44
33
{
45
- label += $ " (<color=#2df7b2>{ ValueTypeName } </color>)";
34
+ m_toStringMethod = ReflectionHelpers . GetActualType ( Value ) . GetMethod ( "ToString" , new Type [ 0 ] )
35
+ ?? typeof ( object ) . GetMethod ( "ToString" , new Type [ 0 ] ) ;
36
+
37
+ // test invoke
38
+ m_toStringMethod . Invoke ( Value , null ) ;
46
39
}
47
- else
40
+ catch
48
41
{
49
- label = label . Replace ( ValueTypeName , $ "<color=#2df7b2> { ValueTypeName } </color>" ) ;
42
+ m_toStringMethod = typeof ( object ) . GetMethod ( "ToString" , new Type [ 0 ] ) ;
50
43
}
44
+ return m_toStringMethod ;
45
+ }
46
+
47
+ private string GetButtonLabel ( )
48
+ {
49
+ string label = ( string ) ToStringMethod ? . Invoke ( Value , null ) ?? Value . ToString ( ) ;
51
50
52
- if ( Value is UnityEngine . Object unityObj && ! label . Contains ( unityObj . name ) )
51
+ var classColor = ValueType . IsAbstract && ValueType . IsSealed
52
+ ? UIStyles . Syntax . Class_Static
53
+ : UIStyles . Syntax . Class_Instance ;
54
+
55
+ if ( Value is UnityEngine . Object )
53
56
{
54
- label = unityObj . name + " | " + label ;
57
+ int typeStart = label . LastIndexOf ( "(" ) ; // get where the '(Type)' starts
58
+ var newLabel = label . Substring ( 0 , typeStart + 1 ) ; // get just the name and first '('
59
+ newLabel += $ "<color={ classColor } >"; // add color tag
60
+ newLabel += label . Substring ( typeStart + 1 ) ; // add the TypeName back in
61
+ newLabel = newLabel . Substring ( 0 , newLabel . Length - 1 ) ; // remove the ending ')'
62
+ newLabel += "</color>)" ; // close color tag and put the ')' back.
63
+ label = newLabel ;
55
64
}
56
-
57
- GUI . skin . button . alignment = TextAnchor . MiddleLeft ;
58
- if ( GUILayout . Button ( label , new GUILayoutOption [ ] { GUILayout . Width ( width - 15 ) } ) )
65
+ else
59
66
{
60
- WindowManager . InspectObject ( Value , out bool _ ) ;
67
+ string classLabel = $ "<color={ classColor } >{ ValueTypeName } </color>";
68
+
69
+ if ( ! label . Contains ( ValueTypeName ) )
70
+ {
71
+ label += $ " ({ classLabel } )";
72
+ }
73
+ else
74
+ {
75
+ label = label . Replace ( ValueTypeName , $ "<color={ classColor } >{ ValueTypeName } </color>") ;
76
+ }
61
77
}
62
- GUI . skin . button . alignment = TextAnchor . MiddleCenter ;
78
+
79
+ return m_btnLabel = label ;
63
80
}
64
81
}
65
82
}
0 commit comments