diff --git a/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs b/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs index 5305bce..d4959a2 100644 --- a/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs +++ b/Alchemy/Assets/Alchemy/Editor/Elements/AlchemyPropertyField.cs @@ -32,8 +32,9 @@ namespace Alchemy.Editor.Elements break; case SerializedPropertyType.Generic: var targetType = property.GetPropertyType(isArrayElement); + var isManagedReferenceProperty = property.propertyType == SerializedPropertyType.ManagedReference; - if (InternalAPIHelper.GetDrawerTypeForType(targetType) != null) + if (InternalAPIHelper.GetDrawerTypeForType(targetType, isManagedReferenceProperty) != null) { element = new PropertyField(property); } diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs index 2fa14cd..407618f 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs @@ -118,10 +118,11 @@ namespace Alchemy.Editor VisualElement element = null; var property = findPropertyFunc(member.Name); + var isManagedReferenceProperty = property?.propertyType == SerializedPropertyType.ManagedReference; // Add default PropertyField if the property has a custom PropertyDrawer - if ((member is FieldInfo fieldInfo && InternalAPIHelper.GetDrawerTypeForType(fieldInfo.FieldType) != null) || - (member is PropertyInfo propertyInfo && InternalAPIHelper.GetDrawerTypeForType(propertyInfo.PropertyType) != null)) + if ((member is FieldInfo fieldInfo && InternalAPIHelper.GetDrawerTypeForType(fieldInfo.FieldType, isManagedReferenceProperty) != null) || + (member is PropertyInfo propertyInfo && InternalAPIHelper.GetDrawerTypeForType(propertyInfo.PropertyType, isManagedReferenceProperty) != null)) { if (property != null) { diff --git a/Alchemy/Assets/Alchemy/Editor/Internal/InternalAPIHelper.cs b/Alchemy/Assets/Alchemy/Editor/Internal/InternalAPIHelper.cs index 47a5379..a659d0a 100644 --- a/Alchemy/Assets/Alchemy/Editor/Internal/InternalAPIHelper.cs +++ b/Alchemy/Assets/Alchemy/Editor/Internal/InternalAPIHelper.cs @@ -18,7 +18,7 @@ namespace Alchemy.Editor const string Name_ScriptAttributeUtility = "UnityEditor.ScriptAttributeUtility"; - public static Type GetDrawerTypeForType(Type classType) + public static Type GetDrawerTypeForType(Type classType, bool isManagedReferenceProperty) { var instance = EditorAssembly.CreateInstance(Name_ScriptAttributeUtility); var utilityType = instance.GetType(); @@ -26,7 +26,23 @@ namespace Alchemy.Editor var bindingFlags = BindingFlags.NonPublic | BindingFlags.Static; var methodInfo = utilityType.GetMethod(nameof(GetDrawerTypeForType), bindingFlags); +#if UNITY_2023_3_OR_NEWER + return (Type)methodInfo.Invoke(instance, new object[] { classType, null, isManagedReferenceProperty }); +#elif UNITY_2023_2_OR_NEWER + // Unity 2023.2.15f1 added a new parameter to the method + var version = UnityEditorInternal.InternalEditorUtility.GetUnityVersion(); + if (version.Build >= 15) + { + return (Type)methodInfo.Invoke(instance, new object[] { classType, isManagedReferenceProperty }); + } + else + { + return (Type)methodInfo.Invoke(instance, new object[] { classType }); + } +#else + _ = isManagedReferenceProperty; // discard return (Type)methodInfo.Invoke(instance, new object[] { classType }); +#endif } const string Name_M_Clickable = "m_Clickable";