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

[Question] How to change how ShowNonSerializedFields are rendered #378

Open
AndrzejKebab opened this issue Dec 18, 2023 · 1 comment
Open

Comments

@AndrzejKebab
Copy link

So I'm doing a RPG game and i have bunch of stats and i would like to have the non serialized values to show at their places in inspector

image

@AndrzejKebab AndrzejKebab changed the title [Question] How to change how ShowNonSerializedFields is rendered [Question] How to change how ShowNonSerializedFields are rendered Dec 18, 2023
@TylerTemp
Copy link

TylerTemp commented Dec 20, 2023

This at this point is not possible, because NA will always render NonSerializedFields and buttons at last.

A workaround is to write a extended script. This is what i use in my project:

gist link

Delete all non-functional (because I have many other drawer extension as well).

This works on my project but because the extensions not included here, and many custom functions I used for myself, so not guaranteed it works in yours. But... you get the idea.

And add a [Ordered] to field if the order is incorrect, then the inspector will know which comes first.


Update: and this is how it looks like in my project. Note the button is in the middle of where it should be.

[SerializeField, Ordered] private int _pIntPrivateOrdered;

[Ordered]
public int pIntOrdered;

[Button("Button Text"), Ordered]
private void MethodTwo() { }

[ShowNativeProperty, Ordered] private string NativeString => "NativeString";
[ShowNonSerializedField, Ordered] private const int NonSerInt = 9;

[Ordered]
public Animator someAnimator;

[AnimatorParam(nameof(someAnimator)), Ordered]
public int paramHash;

FW}KJKN4NI(GU~HZAK`J6


Update: @AndrzejKebab I just notice that the sort function is incorrect...

Please change

_fieldWithInfos.Sort((a, b) =>
{
    // Debug.Assert(a.inherentDepth != 0);
    // Debug.Assert(b.inherentDepth != 0);
    int firstResult = a.inherentDepth.CompareTo(b.inherentDepth);
    return firstResult != 0
        ? firstResult
        : a.order.CompareTo(b.order);
});

Into:

_fieldWithInfos = _fieldWithInfos
    .WithIndex()
    .OrderBy(each => each.value.inherentDepth)
    .ThenBy(each => each.value.order)
    .ThenBy(each => each.index)
    .Select(each => each.value)
    .ToArray();

I have also updated the gist script.

(P.S. I've open-sourced my utils from my old project and published here, if you're interested please consider to have a look. The gist is basiclly this script)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants