post header image for Unity Helpers - Utilities and Extensions for Unity

Unity Helpers - Utilities and Extensions for Unity

3rd June 2014
github
library
open-source
unity
utils

During the development of my up and coming game I have encountered some snags when developing in Unity so I wrote a number of utilities and extension methods to help out.

One such annoyance is the inability to use interfaces in GetComponent() and GetComponents(), so I wrote some extension methods to help with that:

[code lang="csharp"] using UnityHelpers;

var obj = new GameObject(); obj.AddComponent();

obj.Has(); // Returns true or false obj.Has(); // Can also handle interfaces

obj.Get(); // Returns the first component obj.Get(); // Returns the first component that implements the interface

obj.GetAll(); // Gets all the components obj.GetAll(); // Gets all the components that implement the interface [/code]

Another utility is for adding children to GameObjects:

[code lang="csharp"] using UnityHelpers;

var obj = new GameObject();

obj.AddChild("Mike"); // Creates a new GameObject named "Mike" and adds it as a child

var player = obj.AddChild("Dave"); // Creates a new GameObject named "Dave" and adds the component "Player" returning it

obj.AddChild(typeof(Player), typeof(Friendly), typeof(AI)); // Creates a new GameObject and adds a number of components [/code]

There are many other utils and extensions, and more to come.

Checkout the source for more info: https://github.com/mikecann/Unity-Helpers/tree/master/Scripts

I have rigorously unit and battle tested these utils and added them to Github so I can use them in furthur projects. I hope they can be of some use to others too!

SUBSCRIBE TO FUTURE POSTS

COMMENT