Unity Class Generator

Unity Class Generator

One of the first editor tools I did with Unity, it started out as a tool to help me generate class scripts for Unity where all the component references in the hierarchy for the selected gameobject, where the generated script would be attached onto could include those component/transform references in the class. By the time the tool was finished I soon realized it would need a lot more options and customization to be useful for all scenarios though.

The biggest reason I thought this tool would be useful is that when you’re starting out with Unity the first thing a beginner doesn’t have familiarity with is getting the right references for other components in order to really progress with making changes to other components.

Obscured by the fact that components get prettyfied names in the editor, not really a problem when you get used to it though.

Getting a little more obscure, as the below one is in the UI namespace, these are just the default Unity components.

For non unity components and third party plugins these will have even more unfamiliar namespaces, this additional thing to find out when wanting to access parts of those components public methods etc via code can be annoying, and while this class generating editor tool was developed for other reasons. I think now a good editor enhancement would just be to add a [copy namespace] context menu option for when a user right clicks on a component, that would probably be better shortcut to have now.

Because when the script is put on a component, there is no direct way to see  or get the exact namespace or proceeding namespace that the component class is in, something you just start to learn while coding scripts with Unity. Initially you can waste time trying to find it out just so you can write down the correct variable types to access.

Of course by the time this project was getting complete I realized it wouldn’t be all that useful as most the time you don’t really want an entire script of references to other components. If anything its only really useful for the newer UGUI interface framework that got added in Unity5.0 where you might want a main class script to handle all references to other UGUI components in the same hierarchy. Which was kind of the timeframe when I got started with learning Unity was just after its 5.0 release and is a pretty big reason for why I created this editor tool. Anyway you get so familiar with the default component namespaces and classes that it was sort of a redundant tool by the time it was finished.

Unity Class Generator 1

Though it does still come in handy when using third party components and plugins. I may end up reusing the code in this project to create another editor tool that I think would be much more useful for unity editor, or just make that context menu idea… as I write this out, Unity are actually adding in 2 feature ideas into the editor for the 2018 release. I’ll have to write about those, seeing they don’t seem to be crediting me for the ideas even though I wrote about them in detail on there forums a year before they finally got around to implementing them exactly as described and in one case screenshotted from one of my other unity editor mods.

I’ll have to start sticking more of these things down on my this site and credit myself with the proof on all these small little things I do to help out other companies with better ideas and features for doing things.

Leave a Reply

Your email address will not be published. Required fields are marked *