I have a class that has a lot of fields, and want to group them in the inspector.
I know that can be done by using the propertydrawer,
but I’m curious if there’s a simpler way that’s built in into unity, like using
[Header("Header Name")]
which is in the UnityEngine namespace.
Maybe something that looks like this?
[StartDropdown]
float a;
float b;
float c;
[EndDropdown]
I’m not looking for solutions like using lists, enums, or the editor.
Just curious if there’s a built in function similar to the header function mentioned above.
Many thanks in advance!
Not sure of this specific ask, but Odin Inspector and Advanced Inspector on the Asset Store have a ton of handy-dandy decorators to do stuff like this for you.
So nothing built in? Got it
I’ll look into what you suggested! Thanks
No, nothing built-in. However you can get foldouts by “outsourcing” your fields into serializable classes. Of course this changes where the variables are stored and changes how you have to access them. However if you really have many variables this may be useful.
Though a single class shouldn’t have that many variables in the first place. So watch out that you don’t accidentally create a god-object.
Anyways a concrete example would look like this:
[System.Serializable]
public class SubData
{
public float a;
public float b;
public float c;
}
public class YourComponent : MonoBehaviour
{
public SubData subData;
}