Merge pull request #26 from AnnulusGames/fix-inlinefield

Fix: [InlineField] not working
This commit is contained in:
Annulus Games 2024-02-17 15:02:32 +09:00 committed by GitHub
commit 2035c6b37c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 7 deletions

View File

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

View File

@ -3,6 +3,7 @@ using UnityEngine.Assertions;
using UnityEngine.UIElements;
using UnityEditor;
using UnityEditor.UIElements;
using Alchemy.Inspector;
namespace Alchemy.Editor.Elements
{
@ -29,14 +30,23 @@ namespace Alchemy.Editor.Elements
foldout.BindProperty(property);
field = GUIHelper.CreateObjectField(property, type);
field = new ObjectField()
{
label = ObjectNames.NicifyVariableName(property.displayName),
objectType = type,
allowSceneObjects = property.GetFieldInfo().HasCustomAttribute<AssetsOnlyAttribute>(),
value = property.objectReferenceValue
};
field.style.position = Position.Absolute;
field.style.width = Length.Percent(100f);
GUIHelper.ScheduleAdjustLabelWidth(field);
field.schedule.Execute(() =>
OnPropertyChanged(property);
field.RegisterValueChangedCallback(x =>
{
property.objectReferenceValue = x.newValue;
property.serializedObject.ApplyModifiedProperties();
OnPropertyChanged(property);
field.RegisterValueChangeCallback(x => OnPropertyChanged(x.changedProperty));
});
Add(foldout);
@ -44,7 +54,7 @@ namespace Alchemy.Editor.Elements
}
readonly Foldout foldout;
readonly PropertyField field;
readonly ObjectField field;
readonly int depth;
bool isNull;

View File

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