using System; using Alchemy.Inspector; using UnityEditor; using UnityEditor.UIElements; using UnityEngine.Assertions; using UnityEngine.UIElements; namespace Alchemy.Editor.Elements { /// /// Visual Element that draws the ObjectField of the InlineEditor attribute /// public sealed class InlineEditorObjectField : BindableElement { public InlineEditorObjectField(SerializedProperty property, Type type) { Assert.IsTrue(property.propertyType == SerializedPropertyType.ObjectReference); style.minHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; foldout = new Foldout() { text = ObjectNames.NicifyVariableName(property.displayName) }; var toggle = foldout.Q(); var clickable = InternalAPIHelper.GetClickable(toggle); InternalAPIHelper.SetAcceptClicksIfDisabled(clickable, true); foldout.BindProperty(property); inspectorContainer = new VisualElement(); field = new ObjectField() { label = ObjectNames.NicifyVariableName(property.displayName), objectType = type, allowSceneObjects = !property.GetFieldInfo().HasCustomAttribute(), value = property.objectReferenceValue }; field.style.position = Position.Absolute; field.style.width = Length.Percent(100f); GUIHelper.ScheduleAdjustLabelWidth(field); OnPropertyChanged(property); field.RegisterValueChangedCallback(x => { property.objectReferenceValue = x.newValue; property.serializedObject.ApplyModifiedProperties(); OnPropertyChanged(property); }); Add(foldout); Add(field); } readonly Foldout foldout; readonly VisualElement inspectorContainer; readonly ObjectField field; bool isNull; public bool IsObjectNull => isNull; public string Label { get { if (isNull) return field.Q