From a78f5a340fd223d65b58722bf3e45d5369ebe05c Mon Sep 17 00:00:00 2001 From: Makihiro Date: Sat, 3 Aug 2024 23:33:05 +0900 Subject: [PATCH] UIToolKit test --- .../Editor/SubclassSelectorDrawer.cs | 17 ++++++ .../Editor/TypePopupField.cs | 59 +++++++++++++++++++ .../Editor/TypePopupField.cs.meta | 11 ++++ 3 files changed, 87 insertions(+) create mode 100644 Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs create mode 100644 Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs.meta diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs index 5357679..06e1ab3 100644 --- a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/SubclassSelectorDrawer.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using UnityEngine; using UnityEditor; using UnityEditor.IMGUI.Controls; +using UnityEngine.UIElements; +using UnityEditor.UIElements; namespace MackySoft.SerializeReferenceExtensions.Editor { @@ -110,6 +112,21 @@ namespace MackySoft.SerializeReferenceExtensions.Editor EditorGUI.EndProperty(); } + public override VisualElement CreatePropertyGUI (SerializedProperty property) + { + VisualElement root = new VisualElement(); + if (property.propertyType == SerializedPropertyType.ManagedReference) + { + TypePopupField typePopupField = new TypePopupField(property, new VisualElement()); + root.Add(typePopupField); + } + else + { + return new Label(k_IsNotManagedReferenceLabel.text); + } + return root; + } + PropertyDrawer GetCustomPropertyDrawer (SerializedProperty property) { Type propertyType = ManagedReferenceUtility.GetType(property.managedReferenceFullTypename); diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs new file mode 100644 index 0000000..5e47b07 --- /dev/null +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs @@ -0,0 +1,59 @@ +#if UNITY_2019_3_OR_NEWER +using UnityEditor; +using UnityEngine.UIElements; + +namespace MackySoft.SerializeReferenceExtensions.Editor +{ + public sealed class TypePopupField : BaseField + { + + public new static readonly string ussClassName = "unity-base-popup-field"; + + public static readonly string textUssClassName = ussClassName + "__text"; + + public static readonly string arrowUssClassName = ussClassName + "__arrow"; + + public new static readonly string labelUssClassName = ussClassName + "__label"; + + public new static readonly string inputUssClassName = ussClassName + "__input"; + + readonly SerializedProperty m_Property; + + readonly Toggle m_Toggle; + + readonly VisualElement m_ArrowElement; + readonly Label m_TextElement; + + public TypePopupField (SerializedProperty property, VisualElement visualInput) : base(property.displayName, visualInput) + { + m_Property = property; + + style.flexDirection = FlexDirection.Row; + style.flexShrink = 0; + style.flexGrow = 1; + + AddToClassList(ussClassName); + AddToClassList("unity-base-field__aligned"); + AddToClassList("unity-base-field__inspector-field"); + + labelElement.AddToClassList(labelUssClassName); + labelElement.AddToClassList("unity-popup-field__label"); + labelElement.AddToClassList("unity-property-field__label"); + + m_TextElement = new Label(property.displayName) + { + pickingMode = PickingMode.Ignore + }; + m_TextElement.AddToClassList(textUssClassName); + visualInput.AddToClassList(inputUssClassName); + visualInput.Add(m_TextElement); + visualInput.pickingMode = PickingMode.Ignore; + + m_ArrowElement = new VisualElement(); + m_ArrowElement.AddToClassList(arrowUssClassName); + m_ArrowElement.pickingMode = PickingMode.Ignore; + visualInput.Add(m_ArrowElement); + } + } +} +#endif \ No newline at end of file diff --git a/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs.meta b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs.meta new file mode 100644 index 0000000..e11230b --- /dev/null +++ b/Assets/MackySoft/MackySoft.SerializeReferenceExtensions/Editor/TypePopupField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad665a39f1251a14ea9f40c0c9cf3a75 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: