Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fields that hides inherited properties appears multiple times #28

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ public static VisualElement CreateMemberElement(SerializedObject serializedObjec
break;
case FieldInfo:
case PropertyInfo:
if (memberInfo.IsPublic() || memberInfo.HasCustomAttribute<SerializeField>())
var isSerializedMember = false;
if (memberInfo is FieldInfo f) isSerializedMember = f.IsPublic | f.HasCustomAttribute<SerializeField>();
else if (memberInfo is PropertyInfo p) isSerializedMember = p.HasCustomAttribute<SerializeField>();

if (isSerializedMember)
{
var property = findPropertyFunc?.Invoke(memberInfo.Name);

Expand Down
11 changes: 0 additions & 11 deletions Alchemy/Assets/Alchemy/Editor/Internal/MemberInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,5 @@ public static bool TryGetCustomAttribute<T>(this MemberInfo memberInfo, out T re
result = memberInfo.GetCustomAttribute<T>();
return result != null;
}

public static bool IsPublic(this MemberInfo memberInfo)
{
switch (memberInfo)
{
case MethodInfo methodInfo: return methodInfo.IsPublic;
case FieldInfo fieldInfo: return fieldInfo.IsPublic;
case PropertyInfo propertyInfo: return propertyInfo.GetMethod != null && propertyInfo.GetMethod.IsPublic && propertyInfo.SetMethod != null && propertyInfo.SetMethod.IsPublic;
default: throw new NotSupportedException();
}
}
}
}