From f6526b3cc1a71b59d0b31871e9f719aaba6ec072 Mon Sep 17 00:00:00 2001 From: AnnulusGames Date: Sat, 17 Feb 2024 14:50:56 +0900 Subject: [PATCH 1/2] Change: rename method --- .../Alchemy/Editor/Elements/AlchemyPropertyField.cs | 4 ++-- .../Alchemy/Editor/Elements/InlineEditorObjectField.cs | 9 +++------ Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs index a954d10..f5102e3 100644 --- a/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs +++ b/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs @@ -30,12 +30,12 @@ namespace Alchemy.Editor.Elements } else { - element = GUIHelper.CreateObjectField(property, type); + element = GUIHelper.CreateObjectPropertyField(property, type); } break; case SerializedPropertyType.Generic: var targetType = property.GetPropertyType(isArrayElement); - + if (InternalAPIHelper.GetDrawerTypeForType(targetType) != null) { element = new PropertyField(property); diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs index eb1e091..5155496 100644 --- a/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs +++ b/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs @@ -29,15 +29,12 @@ namespace Alchemy.Editor.Elements foldout.BindProperty(property); - field = GUIHelper.CreateObjectField(property, type); + field = GUIHelper.CreateObjectPropertyField(property, type); field.style.position = Position.Absolute; field.style.width = Length.Percent(100f); - field.schedule.Execute(() => - { - OnPropertyChanged(property); - field.RegisterValueChangeCallback(x => OnPropertyChanged(x.changedProperty)); - }); + // OnPropertyChanged(property); + field.RegisterValueChangeCallback(x => OnPropertyChanged(x.changedProperty)); Add(foldout); Add(field); diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs index 3acf018..6637099 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/GUIHelper.cs @@ -51,7 +51,7 @@ namespace Alchemy.Editor }; } - public static PropertyField CreateObjectField(SerializedProperty property, Type type) + public static PropertyField CreateObjectPropertyField(SerializedProperty property, Type type) { Assert.IsTrue(property.propertyType == SerializedPropertyType.ObjectReference); From c463f368822599a14563589276a8549b5d70c151 Mon Sep 17 00:00:00 2001 From: AnnulusGames Date: Sat, 17 Feb 2024 15:00:00 +0900 Subject: [PATCH 2/2] Fix: InlineField attribute not working --- .../Elements/InlineEditorObjectField.cs | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs index 5155496..dc12312 100644 --- a/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs +++ b/Alchemy/Assets/Alchemy/Editor/Elements/InlineEditorObjectField.cs @@ -3,6 +3,7 @@ using UnityEngine.Assertions; using UnityEngine.UIElements; using UnityEditor; using UnityEditor.UIElements; +using Alchemy.Inspector; namespace Alchemy.Editor.Elements { @@ -29,19 +30,31 @@ namespace Alchemy.Editor.Elements foldout.BindProperty(property); - field = GUIHelper.CreateObjectPropertyField(property, type); + 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.RegisterValueChangeCallback(x => OnPropertyChanged(x.changedProperty)); + OnPropertyChanged(property); + field.RegisterValueChangedCallback(x => + { + property.objectReferenceValue = x.newValue; + property.serializedObject.ApplyModifiedProperties(); + OnPropertyChanged(property); + }); Add(foldout); Add(field); } readonly Foldout foldout; - readonly PropertyField field; + readonly ObjectField field; readonly int depth; bool isNull;