dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.53k stars 464 forks source link

Inside serialized item list, show if and enable if not works #377

Open mmar58 opened 10 months ago

mmar58 commented 10 months ago

`public class TimelineItem {

string name = "";
public TimelineItem()
{

    name = "TImeline Elemenet";
}
public bool label;
[NaughtyAttributes.ShowIf("label")]
public string LabelText = "Round 1";
public List<VideoItem> videos = new List<VideoItem>();
public bool loop;
[NaughtyAttributes.ShowIf("ShouldShowLoop")]
public int loopCount=1;
public bool startTimer;
[NaughtyAttributes.ShowIf("startTimer")]
public float timerTime = 60;
bool ShouldShowLoop()
{
    return loop&&!label;
}

} [Serializable] public class VideoItem { List titles = new(); [Dropdown("titles")] public string value; public VideoItem() { titles = TimelineCreator.sectionTitles; } }`

This is my class and I am using [SerializeField] List<TimelineItem> Timeline = new(); in the mono behavior. The dropdown is working great, no matter how deep it is. But the show if and enable if isn't working inside the list view.

So I will be greatful if you fix this issue. But I loved your work, thanks, will use it in every project I will create.

TylerTemp commented 7 months ago

NaughtyAttributes only works as CustomEditor and PropertyAttributeDrawer, which does not work on Serializable

A working one is here but you need to switch the decorator inside Serialieable from NA to SaintsField's version

[Serializable]
public class VideoItem
{
    // DeEditorUtils.List titles = new();
    [Dropdown("titles"), BelowRichLabel(nameof(value), true)]
    public string value;

    public DropdownList<string> titles = new DropdownList<string>
    {
        { "Example1", "Example1" },
        { "Example2", "Example2" },
        { "Example3", "Example3" },
    };

    public VideoItem() {
        // titles = TimelineCreator.sectionTitles;
    }
}

// [SaintsRow] public VideoItem[] videoItem;

[Serializable]
public class TimelineItem
{

    string name = "";
    public TimelineItem()
    {

        name = "TImeline Elemenet";
    }
    public bool label;
    [ShowIf("label")]
    public string LabelText = "Round 1";
    [SaintsRow]
    public List<VideoItem> videos = new List<VideoItem>();
    public bool loop;
    [ShowIf("ShouldShowLoop")]
    public int loopCount=1;
    public bool startTimer;
    [ShowIf("startTimer")]
    public float timerTime = 60;
    bool ShouldShowLoop()
    {
        return loop&&!label;
    }

}

[SerializeField, SaintsRow] List<TimelineItem> Timeline = new List<TimelineItem>();

image