I’d love to be able to make some of my scripts have collapsing sections in the editor because they have a lot of variables and can it would just be nice for them to be more organised but it seems like a lot of work to get that happening, I feel I must be getting something wrong.
So do I have to make an editor script that references the target script, and then make a variable for each variable in the target script and then hook them up? Then I can add something to collapse that section?
I’ve searched through a bunch of posts on the subject but they seem really dated and are saying to use attributes, which are great but don’t allow folding sections (it would be cool if there was a way to do it through those) or making classes, but that seems way too hacky.
Is there an easy way? I just don’t want to have to manage 2 scripts and duplicates of every variable to get this working.
Probably the easiest way is to put groups of your variables into their own classes, then have an instance of each of those classes. The inspector will then allow you to open/close them. Obviously the use sites would have to change slightly, to be prefixed with the instances.
If you want to see an example, look at the FirstPersonController.cs script that comes with Unity Standard Assets, specifically what they did with MouseLook and FOVKick for instance (and other such classes).
But on another note, with a component system like Unity, you may get benefit from refactoring your scripts to break them down into more-logical pieces that will allow you to get a better handle on having so much configurable space.
Thanks,
I’m looking into refactoring a bit and it’s helping, maybe after that if it’s still looking bad, I’ll dive into the editor script. It’s probably about time I got into it.
Found these nice little pointers for VSCode - Refactoring with Visual Studio Code