11
11
namespace TNRD
12
12
{
13
13
[ CustomPropertyDrawer ( typeof ( SerializableInterface < > ) , true ) ]
14
- internal sealed class SerializableInterfacePropertyDrawer : PropertyDrawer
14
+ internal sealed partial class SerializableInterfacePropertyDrawer : PropertyDrawer
15
15
{
16
16
private SerializedProperty serializedProperty ;
17
- private bool isSelected ;
17
+ private bool labelSelected ;
18
+ private bool objectPickerSelected ;
19
+
20
+ private bool IsSelected => labelSelected || objectPickerSelected ;
18
21
19
22
private SerializedProperty RawReferenceProperty => serializedProperty . FindPropertyRelative ( "rawReference" ) ;
20
23
private SerializedProperty UnityReferenceProperty => serializedProperty . FindPropertyRelative ( "unityReference" ) ;
@@ -81,7 +84,6 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
81
84
HandleDeleteButton ( ) ;
82
85
}
83
86
84
-
85
87
private Type GetGenericArgument ( )
86
88
{
87
89
Type type = fieldInfo . FieldType ;
@@ -118,7 +120,7 @@ Type genericArgument
118
120
height = EditorGUIUtility . singleLineHeight
119
121
} ;
120
122
121
- objectFieldRect = EditorGUI . PrefixLabel ( objectFieldRect , label ) ;
123
+ objectFieldRect = DrawPrefixLabel ( objectFieldRect , label ) ;
122
124
DrawRawReference ( objectFieldRect ) ;
123
125
DrawButton ( objectFieldRect , property , genericArgument ) ;
124
126
@@ -150,7 +152,7 @@ private void DrawUnityReferenceMode(
150
152
Type genericArgument
151
153
)
152
154
{
153
- position = EditorGUI . PrefixLabel ( position , label ) ;
155
+ position = DrawPrefixLabel ( position , label ) ;
154
156
DrawUnityReference ( position ) ;
155
157
DrawButton ( position , property , genericArgument ) ;
156
158
}
@@ -163,8 +165,30 @@ private void DrawUnityReference(Rect position)
163
165
DrawObjectField ( position , EditorGUIUtility . ObjectContent ( unityReference , referenceType ) , unityReference ) ;
164
166
}
165
167
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
+
166
187
private void DrawObjectField ( Rect position , GUIContent objectFieldContent , Object objectToShow )
167
188
{
189
+ Rect positionWithoutThumb = new Rect ( position ) ;
190
+ positionWithoutThumb . xMax -= 20 ;
191
+
168
192
Event evt = Event . current ;
169
193
if ( evt . type == EventType . Repaint )
170
194
{
@@ -173,14 +197,29 @@ private void DrawObjectField(Rect position, GUIContent objectFieldContent, Objec
173
197
position . Contains ( evt . mousePosition ) ,
174
198
false ,
175
199
false ,
176
- isSelected ) ;
200
+ IsSelected ) ;
177
201
}
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 )
179
217
{
180
- isSelected = position . Contains ( evt . mousePosition ) ;
218
+ objectPickerSelected = positionWithoutThumb . Contains ( evt . mousePosition ) ;
219
+ PingObject ( ) ;
181
220
RepaintActiveInspector ( ) ;
182
221
}
183
- else if ( evt . type == EventType . MouseDown && evt . button == 1 && position . Contains ( evt . mousePosition ) )
222
+ else if ( evt . button == 1 && positionWithoutThumb . Contains ( evt . mousePosition ) )
184
223
{
185
224
if ( objectToShow != null )
186
225
{
@@ -195,6 +234,24 @@ private void DrawObjectField(Rect position, GUIContent objectFieldContent, Objec
195
234
}
196
235
}
197
236
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
+
198
255
private void RepaintActiveInspector ( )
199
256
{
200
257
// 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
263
320
264
321
private void HandleDeleteButton ( )
265
322
{
266
- if ( ! isSelected )
323
+ if ( ! IsSelected )
267
324
return ;
268
325
269
326
Event evt = Event . current ;
0 commit comments