1111namespace TNRD
1212{
1313 [ CustomPropertyDrawer ( typeof ( SerializableInterface < > ) , true ) ]
14- internal sealed class SerializableInterfacePropertyDrawer : PropertyDrawer
14+ internal sealed partial class SerializableInterfacePropertyDrawer : PropertyDrawer
1515 {
1616 private SerializedProperty serializedProperty ;
17- private bool isSelected ;
17+ private bool labelSelected ;
18+ private bool objectPickerSelected ;
19+
20+ private bool IsSelected => labelSelected || objectPickerSelected ;
1821
1922 private SerializedProperty RawReferenceProperty => serializedProperty . FindPropertyRelative ( "rawReference" ) ;
2023 private SerializedProperty UnityReferenceProperty => serializedProperty . FindPropertyRelative ( "unityReference" ) ;
@@ -81,7 +84,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
8184 HandleDeleteButton ( ) ;
8285 }
8386
84-
8587 private Type GetGenericArgument ( )
8688 {
8789 Type type = fieldInfo . FieldType ;
@@ -118,7 +120,7 @@ Type genericArgument
118120 height = EditorGUIUtility . singleLineHeight
119121 } ;
120122
121- objectFieldRect = EditorGUI . PrefixLabel ( objectFieldRect , label ) ;
123+ objectFieldRect = DrawPrefixLabel ( objectFieldRect , label ) ;
122124 DrawRawReference ( objectFieldRect ) ;
123125 DrawButton ( objectFieldRect , property , genericArgument ) ;
124126
@@ -150,7 +152,7 @@ private void DrawUnityReferenceMode(
150152 Type genericArgument
151153 )
152154 {
153- position = EditorGUI . PrefixLabel ( position , label ) ;
155+ position = DrawPrefixLabel ( position , label ) ;
154156 DrawUnityReference ( position ) ;
155157 DrawButton ( position , property , genericArgument ) ;
156158 }
@@ -163,8 +165,30 @@ private void DrawUnityReference(Rect position)
163165 DrawObjectField ( position , EditorGUIUtility . ObjectContent ( unityReference , referenceType ) , unityReference ) ;
164166 }
165167
168+ private Rect DrawPrefixLabel ( Rect position , GUIContent label )
169+ {
170+ GUIStyle labelStyle = IsSelected ? Styles . SelectedLabelStyle : Styles . RegularLabelStyle ;
171+ Rect result = EditorGUI . PrefixLabel ( position , label , labelStyle ) ;
172+
173+ if ( Event . current . type == EventType . MouseDown )
174+ {
175+ Rect delta = new Rect ( position )
176+ {
177+ width = position . width - result . width
178+ } ;
179+
180+ labelSelected = delta . Contains ( Event . current . mousePosition ) ;
181+ RepaintActiveInspector ( ) ;
182+ }
183+
184+ return result ;
185+ }
186+
166187 private void DrawObjectField ( Rect position , GUIContent objectFieldContent , Object objectToShow )
167188 {
189+ Rect positionWithoutThumb = new Rect ( position ) ;
190+ positionWithoutThumb . xMax -= 20 ;
191+
168192 Event evt = Event . current ;
169193 if ( evt . type == EventType . Repaint )
170194 {
@@ -173,14 +197,29 @@ private void DrawObjectField(Rect position, GUIContent objectFieldContent, Objec
173197 position . Contains ( evt . mousePosition ) ,
174198 false ,
175199 false ,
176- isSelected ) ;
200+ IsSelected ) ;
177201 }
178- else if ( ( evt . type == EventType . MouseDown || evt . type == EventType . MouseUp ) && evt . button == 0 )
202+
203+ HandleObjectFieldMouseDown ( position , objectToShow , evt , positionWithoutThumb ) ;
204+ }
205+
206+ private void HandleObjectFieldMouseDown (
207+ Rect position ,
208+ Object objectToShow ,
209+ Event evt ,
210+ Rect positionWithoutThumb
211+ )
212+ {
213+ if ( evt . type != EventType . MouseDown )
214+ return ;
215+
216+ if ( evt . button == 0 )
179217 {
180- isSelected = position . Contains ( evt . mousePosition ) ;
218+ objectPickerSelected = positionWithoutThumb . Contains ( evt . mousePosition ) ;
219+ PingObject ( ) ;
181220 RepaintActiveInspector ( ) ;
182221 }
183- else if ( evt . type == EventType . MouseDown && evt . button == 1 && position . Contains ( evt . mousePosition ) )
222+ else if ( evt . button == 1 && positionWithoutThumb . Contains ( evt . mousePosition ) )
184223 {
185224 if ( objectToShow != null )
186225 {
@@ -195,6 +234,24 @@ private void DrawObjectField(Rect position, GUIContent objectFieldContent, Objec
195234 }
196235 }
197236
237+ private void PingObject ( )
238+ {
239+ if ( ! IsSelected )
240+ return ;
241+
242+ switch ( ReferenceMode )
243+ {
244+ case ReferenceMode . Raw :
245+ // No support for pinging raw objects for now (I guess this would ping the MonoScript?)
246+ break ;
247+ case ReferenceMode . Unity :
248+ EditorGUIUtility . PingObject ( UnityReferenceProperty . objectReferenceValue ) ;
249+ break ;
250+ default :
251+ throw new ArgumentOutOfRangeException ( ) ;
252+ }
253+ }
254+
198255 private void RepaintActiveInspector ( )
199256 {
200257 // Forcing a repaint of the inspector for this object, not the prettiest but it works
@@ -263,7 +320,7 @@ private void DropdownOnItemSelectedEvent(SerializedProperty property, ReferenceM
263320
264321 private void HandleDeleteButton ( )
265322 {
266- if ( ! isSelected )
323+ if ( ! IsSelected )
267324 return ;
268325
269326 Event evt = Event . current ;
0 commit comments