mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 00:08:53 -05:00
Fix: Resolved InternalAPIHelper error in Unity 2023.2.15f1 and later versions
This commit is contained in:
parent
93a56757a8
commit
2c1f6700a3
@ -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);
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user