AnnulusGames / LucidEditor

Powerful Editor Extensions for Unity
MIT License
127 stars 13 forks source link

Class Editor won't show (and throws errors) when parent class has private serialized fields #1

Closed cji3bp62000 closed 1 year ago

cji3bp62000 commented 1 year ago

This is my First time for posting an issue, so if the format is bad, I will change it.

First of all, thanks for the fantastic library! This library really helps me a lot.

When using this library, I found an issue that, the editor of a class that inherit from a base class with private SerializedField won't show, and keep throwing error of:

ArgumentException: Could not find the field or property of property
AnnulusGames.LucidTools.Editor.SerializedPropertyExtensions.GetAttributes[TAttribute] (UnityEditor.SerializedProperty property, System.Boolean inherit) (at ***/PackageCache/com.annulusgames.lucid-editor@0bf342eaec/Editor/Extensions/SerializedPropertyExtensions.cs:87)

example:

public class BaseClass : MonoBehaviour
{
    [SerializedField] private bool somePrivateField;
}

// in another file
public class InheritClass : BaseClass
{
    // the editor of this class won't show
    [SerializedField] private bool someFieldInInheritClass;
}
ScreenShot

 

I found out that SerializedPropertyExtensions.GetAttributes() is using Type.GetField() to retrieve types, but GetField() can't retrieve members that the type can't see (= private members in parent class). I think this is the reason.

Edit: By the same reason, base class's private method with [Button] attribute won't show in editor of inherit classes. (There are other similar issues with the same reason I think)

AnnulusGames commented 1 year ago

Thank you for using Lucid Editor!

I fixed the bug you pointed out and released it as v1.0.1. I would appreciate it if you could confirm it.