Compare commits

...

1 Commits

Author SHA1 Message Date
Makihiro
a78f5a340f UIToolKit test 2024-08-03 23:33:05 +09:00
3 changed files with 87 additions and 0 deletions

View File

@ -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);

View File

@ -0,0 +1,59 @@
#if UNITY_2019_3_OR_NEWER
using UnityEditor;
using UnityEngine.UIElements;
namespace MackySoft.SerializeReferenceExtensions.Editor
{
public sealed class TypePopupField : BaseField<object>
{
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

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ad665a39f1251a14ea9f40c0c9cf3a75
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: