Skip to content

Commit a78f5a3

Browse files
committed
UIToolKit test
1 parent 69f6e31 commit a78f5a3

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
using UnityEngine;
66
using UnityEditor;
77
using UnityEditor.IMGUI.Controls;
8+
using UnityEngine.UIElements;
9+
using UnityEditor.UIElements;
810

911
namespace MackySoft.SerializeReferenceExtensions.Editor
1012
{
@@ -110,6 +112,21 @@ public override void OnGUI (Rect position, SerializedProperty property, GUIConte
110112
EditorGUI.EndProperty();
111113
}
112114

115+
public override VisualElement CreatePropertyGUI (SerializedProperty property)
116+
{
117+
VisualElement root = new VisualElement();
118+
if (property.propertyType == SerializedPropertyType.ManagedReference)
119+
{
120+
TypePopupField typePopupField = new TypePopupField(property, new VisualElement());
121+
root.Add(typePopupField);
122+
}
123+
else
124+
{
125+
return new Label(k_IsNotManagedReferenceLabel.text);
126+
}
127+
return root;
128+
}
129+
113130
PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property)
114131
{
115132
Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#if UNITY_2019_3_OR_NEWER
2+
using UnityEditor;
3+
using UnityEngine.UIElements;
4+
5+
namespace MackySoft.SerializeReferenceExtensions.Editor
6+
{
7+
public sealed class TypePopupField : BaseField<object>
8+
{
9+
10+
public new static readonly string ussClassName = "unity-base-popup-field";
11+
12+
public static readonly string textUssClassName = ussClassName + "__text";
13+
14+
public static readonly string arrowUssClassName = ussClassName + "__arrow";
15+
16+
public new static readonly string labelUssClassName = ussClassName + "__label";
17+
18+
public new static readonly string inputUssClassName = ussClassName + "__input";
19+
20+
readonly SerializedProperty m_Property;
21+
22+
readonly Toggle m_Toggle;
23+
24+
readonly VisualElement m_ArrowElement;
25+
readonly Label m_TextElement;
26+
27+
public TypePopupField (SerializedProperty property, VisualElement visualInput) : base(property.displayName, visualInput)
28+
{
29+
m_Property = property;
30+
31+
style.flexDirection = FlexDirection.Row;
32+
style.flexShrink = 0;
33+
style.flexGrow = 1;
34+
35+
AddToClassList(ussClassName);
36+
AddToClassList("unity-base-field__aligned");
37+
AddToClassList("unity-base-field__inspector-field");
38+
39+
labelElement.AddToClassList(labelUssClassName);
40+
labelElement.AddToClassList("unity-popup-field__label");
41+
labelElement.AddToClassList("unity-property-field__label");
42+
43+
m_TextElement = new Label(property.displayName)
44+
{
45+
pickingMode = PickingMode.Ignore
46+
};
47+
m_TextElement.AddToClassList(textUssClassName);
48+
visualInput.AddToClassList(inputUssClassName);
49+
visualInput.Add(m_TextElement);
50+
visualInput.pickingMode = PickingMode.Ignore;
51+
52+
m_ArrowElement = new VisualElement();
53+
m_ArrowElement.AddToClassList(arrowUssClassName);
54+
m_ArrowElement.pickingMode = PickingMode.Ignore;
55+
visualInput.Add(m_ArrowElement);
56+
}
57+
}
58+
}
59+
#endif

Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)