Unity Tools

MIT
by pandarrr

Workflow tools to aid development in Unity

( Crawled 4 months ago )
+

Various tools that have improved my general workflow when developing in Unity.

AutoBehaviour & Attributes

The AutoBehaviour class is used simply to automatically populate public GameObject references. By default it will choose the first Transform it finds that matches the variable's name. The various attributes can be added to a variable to give it more specific directions on which object to find. I prefer specifying the reference in code this way to digging through the hierarchy in the editor.

Assets

This class is generated with T4. The result is a nested class hierarchy that mimics that directory hierarchy of the provided path.

var path = "C:/Projects/Lasers/Assets/Resources";

In this project I have placed all art and prefabs in the 'Resources' directory. This has to be done so the assets can be found with Resources.Load. The directory hiearchy looks like this:

Resources
  Prefabs
    CannonBalls
  Sprites

The root class is called Assets. Starting from the root directory, each subdirectory is a nested class with associated member and each file is a member. Say I have a prefab called 'CannonBall' in the 'CannonBalls' directory. This prefab can be used in code like this:

var ball = Instantiate(Assets.Prefabs.CannonBalls.CannonBall);

The type of the member is determined by the files extension. A member will not be created for undefined file types.

var assetTypes = new Dictionary<string, string> { { ".prefab", "GameObject" }, { ".png", "Sprite" } };

The generated script needs to be attached to a GameObject in the scene. It derives from AutoBehaviour, so just click the Populate button and every reference will be automatically mapped. Each nested class is also serialized so the entire class hierarchy can be viewed in the editor to ensure the fields are actually mapped.