Skip to content

Commit 209d461

Browse files
committed
feat: Allowed making additional actions on type selection and manually triggering dropdown
1 parent 0ae12b7 commit 209d461

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Editor/Drawers/TypeFieldDrawer.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// <summary>
1313
/// Draws a <see cref="TypeReference"/> field and handles control over the drop-down list.
1414
/// </summary>
15-
internal struct TypeFieldDrawer
15+
internal class TypeFieldDrawer
1616
{
1717
private const string MissingSuffix = " {Missing}";
1818
private static readonly int _controlHint = typeof(TypeReferencePropertyDrawer).GetHashCode();
@@ -22,23 +22,27 @@ internal struct TypeFieldDrawer
2222
private readonly TypeDropdownDrawer _dropdownDrawer;
2323
private readonly bool _showShortName;
2424
private readonly bool _useBuiltInNames;
25-
2625
private readonly Rect _position;
26+
private readonly Action<Type> _onTypeSelected;
27+
2728
private bool _triggerDropDown;
2829

2930
public TypeFieldDrawer(
3031
SerializedTypeReference serializedTypeRef,
3132
Rect position,
3233
TypeDropdownDrawer dropdownDrawer,
3334
bool showShortName,
34-
bool useBuiltInNames)
35+
bool useBuiltInNames,
36+
Action<Type> onTypeSelected = null,
37+
bool triggerDropDown = false)
3538
{
3639
_serializedTypeRef = serializedTypeRef;
3740
_position = position;
3841
_dropdownDrawer = dropdownDrawer;
3942
_showShortName = showShortName;
4043
_useBuiltInNames = useBuiltInNames;
41-
_triggerDropDown = false;
44+
_onTypeSelected = onTypeSelected;
45+
_triggerDropDown = triggerDropDown;
4246
}
4347

4448
public void Draw()
@@ -52,13 +56,18 @@ public void Draw()
5256
private void DrawTypeSelectionControl()
5357
{
5458
int controlID = GUIUtility.GetControlID(_controlHint, FocusType.Keyboard, _position);
55-
_triggerDropDown = false;
5659
ReactToCurrentEvent(controlID);
5760

5861
if ( ! _triggerDropDown)
5962
return;
6063

61-
_dropdownDrawer.Draw(OnTypeSelected);
64+
_triggerDropDown = false;
65+
66+
_dropdownDrawer.Draw(type =>
67+
{
68+
OnTypeSelected(type);
69+
_onTypeSelected?.Invoke(type);
70+
});
6271
}
6372

6473
private void ReactToCurrentEvent(int controlID)

0 commit comments

Comments
 (0)