dbrizov / NaughtyAttributes

Attribute Extensions for Unity
MIT License
4.57k stars 465 forks source link

Feature request - order for box groups #381

Open novavision opened 10 months ago

novavision commented 10 months ago

First of all thanks a lot for your asset, it is just a gem! Made my project looks much more organized.

Working with NestedAttributes for a pretty long time I experienced that I miss order option for some attributes . For example BoxGroup - I have about 4 inheritors and each of them have some specific serialized fields I place under the BoxGroup. In some cases I wish to see very specific BoxGroup on top of all others just for better accessibility and prettier visuals. That's also because some classes have too many fields and may take the area of entire screen height. Foldout BoxGroup may be very handy here as well, but that's a different story.

I there an option to add some order parameter to BoxGroup attribute?

TylerTemp commented 9 months ago

Unfortunately this project hasn't merge PR for years... Here is one that might fit your need (though not exactly what you want) (It's very new so might be buggy)

to demo:

public class RootClass : MonoBehaviour
{
    public string root1;
    public string root2;

    [Layout("RootGroup", ELayout.Title | ELayout.Background | ELayout.TitleOut)]
    public int firstInt;
    [Layout("RootGroup")]
    public int secondInt;

    public string rootAfterGroup;
}

public class Sub1 : RootClass
{
    [Layout("RootGroup")] public int sub1ToRoot;

    public string sub1Item1;

    [Layout("Sub1Group", ELayout.Title | ELayout.Background)] public int sub1Group1, sub1Group2;

    public string sub1ItemAfterGroup;
}

public class Sub2: RootClass
{
    [Layout("RootGroup")] public int sub2ToRoot;

    public string sub2Item1;

    [Layout("Sub2Group", ELayout.Title | ELayout.Background)] public int sub2Group1, sub2Group2;

    public string sub2ItemAfterGroup;
}

Result:

image

So the field stay at the position by the order of declaration and inheriting, but also gets pumped to the first group when necessary.

As for "to see very specific BoxGroup on top of all others", the Ordered attribute might help

novavision commented 9 months ago

@TylerTemp looks cool, thanks. Did I correctly understand that your asset expand same base functionality NaughtyAttributes has? In other words I don't need to do some migration renaming attributes?

TylerTemp commented 9 months ago

@TylerTemp looks cool, thanks. Did I correctly understand that your asset expand same base functionality NaughtyAttributes has? In other words I don't need to do some migration renaming attributes?

Unfortunately, the renderer behavior (demonstrated here, the Layout), is the Editor level function. I quote from NA's documents:

The attributes that won't work in your custom editors are the meta attributes and some drawer attributes such as ReorderableList, Button, ShowNonSerializedField and ShowNativeProperty.

the meta attributes, or the Editor level functions I mentioned here, is NOT compatible with each other: Odin, NaughtyAttributes, MarkupAttributes, SaintsField.SaintsEditor -- only one can work at a time.

In short, there are only 3 options possible: