• This repository has been archived on 12/Aug/2022
  • Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A set of utils and extensions for making unity development easier

NOTE

I havent updated this project in a long time, so I have archived it. Please dont use it unless you are aware that its probably very much out of date :)


Unity-Helpers

A set of utils and extensions for making unity development easier.

Unity is a great tool for making games however there are a few annoyances with its API that I have tried to fix with this library.

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

using UnityHelpers;

var obj = new GameObject();
obj.AddComponent<MyComponent>();

obj.Has<MyComponent>(); // Returns true or false 
obj.HasComponentOrInterface<IMyComponent>(); // Can also handle interfaces

obj.Get<MyComponent>(); // Returns the first component
obj.GetComponentOrInterface<IMyComponent>(); // Returns the first component that implements the interface

obj.GetAll<MyComponent>(); // Gets all the components
obj.GetAllComponentsOrInterfaces<IMyComponent>(); // Gets all the components that implement the interface

Another utility is for adding children to GameObjects:

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<Player>("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

There are a number of useful utils for loading assets into GameObjects too:

using UnityHelpers;

var obj = new GameObject();

obj.Load("Prefabs/Spaceship"); // Loads the Spaceship prefab from the Resources folder and adds it as a child

Most of the Utils also can be accessed via the UnityUtils.* class too rather than just extension methods:

using UnityHelerps;

var player = UnityUtils.Load<Player>("Prefabs/Spaceship");

Enumerate Resources

enumerate resources

Enumerate Resources is a handy util for creating type-safe resource references. Traditionally you have to manually create constant strings to load resources at runtime:

Resources.Load("Prefabs/Cars/Porsche");

This is fragile. If the asset is moved you wont know about the crash until you run the game, this line of code may not be executed often and hence introduces a bug that may only present itself at a later date.

Enumerate Resources scans a resources directory and generates a type-safe alternative:

Resources.Load(GameResources.Prefabs.Cars.Porsche);

Now if you move the resource and run the enumerator you will get a compile error.

For added sugar there is a method to add the loaded resource as a child of a game object (handy for prefabs):

obj.LoadChild(GameResources.Prefabs.Icons.IndicatorArror);

ViewStateController

view state controller screenshot

The ViewStateController is a utility for UnityUI that allows you to manage view states. Simply add the states to a list then use the dropdown in the inspector to toggle between which one is active.

At runtime use the methods to change the states:

var states = GetComponent<ViewStateController>();

states.SetState("Main Menu"); // Sets the main menu state

states.SetState(someOtherStateGameObject); // Sets another state using the gameobject reference

FPSCounter

Attach this component to a gameobject with a Text component and output the current FPS to the screen.

Misc Hacks

The UnityHelpers.MiscHacks class contains a few helpful hacks, such as opening the SpriteEditorWindow directly from code (Unity provides no way of doing this).

Tests

I have included a number of Unit Tests with the project. If you would like to run the tests yourself then just make sure you include the "Unity Test Tools" project from the asset store.

Installation

Simply include the source in your project, to use the extension methods dont forget to include the namespace:

using UnityHelpers;

More Repositories

1

clouds-and-edges

Some experiments with Cloudflare's Durable Objects
TypeScript
70
star
2

Chrome-Crawler

An extension for google chrome that lets a use crawl a webpage for files and links
JavaScript
68
star
3

Unity-Ash

A Unity port of Richard Lord's Ash Game Framework
C#
50
star
4

disco-cube-daemon

TypeScript
35
star
5

disco-cube-admin

The admin panel for my discocube project
TypeScript
34
star
6

mst-log

A console logging middleware for MobX State Tree
TypeScript
27
star
7

Windows7-Taskbar-Monitor

At-a-glance monitoring of essential system performance.
C#
24
star
8

react-hooks-chrome-extension

A sample repo showing how to use react hooks to write chrome extensions
TypeScript
23
star
9

Recursive

A chrome extension web crawler written in Typescript / Javascript
JavaScript
20
star
10

mst-flow-pipe

helper function for creating type-safe generators for mobx-state-tree
TypeScript
18
star
11

Swft

A Dependency Injection & Signals Enhanced Component Based Game Framework
ActionScript
17
star
12

UnityAshteroids

An example for the Unity-Ash game framwork
C#
17
star
13

Unity-Parse-Helpers

Type-safe extensions and helpers for using Parse.com in Unity
C#
16
star
14

Hxaria

Messing around with a Terraria like terrain in haXe
JavaScript
15
star
15

WebGLTerrainicles

GPU based particle simulation with haXe and WebGL
JavaScript
11
star
16

RobotLegs2Hx

Haxe port of RobotLegs2
Haxe
10
star
17

Entitasteroids

An asteroids example game build using Entitas for Unity
C#
10
star
18

ParseUnitySampleProject

A beginning project structure for using Parse.com in Unity
C#
9
star
19

SwiftSuspendersHx

Haxe Port of SwiftSuspenders 2
Haxe
9
star
20

HaxeWebGLParticles

WebGL Particle Experiment With Haxe
Haxe
9
star
21

Ectoplasm

AS3 mobile game using Ash and Starling
ActionScript
7
star
22

Swift-Examples

A collection of examples for the Swft framework
ActionScript
6
star
23

MrNibblesML

example project combining Mr Nibbles and Machine Learning
C#
6
star
24

ThreadX

A Twitter / X / Threads clone built using Convex.dev
TypeScript
4
star
25

chat-for-trello

A chrome extension that enabled chat right inside of Trello Desktop https://trello.com/b/Mdpd40Tt/trello-chat
CSS
3
star
26

PrintomiMaps

Taking some images from Printomi and turning them into giant google maps
C#
2
star
27

mixcloud-dl

A CLI that makes mixcloud mixes available offline
TypeScript
2
star
28

mikecann.co.uk

next-mikecann
TypeScript
2
star
29

typescript-react-HMR-chrome-extension-starter

How I want to build my chrome extensions
TypeScript
2
star
30

gatsby_mikecann.co.uk

My Blog
TypeScript
2
star
31

chatter-craft

Collaborate on a shared canvas using just your voice
TypeScript
1
star
32

Unity-Ash-Performance-Tests

Some performance tests for the Unity-Ash project
C#
1
star
33

mikeysee-chrome-extension-helpers

A bunch of helpers for writing chrome extetnsions
TypeScript
1
star
34

MCTestGit

Testing git-ness
1
star
35

Portal2D-XNA

University project. The rudiments of a 2D version of portal.
C#
1
star
36

new-tab-chrome-experiments

A new Chrome Experiment each time you open a new tab!
TypeScript
1
star
37

Audiobook-Organiser

A tool for quickly and easily organising your audiobook collection
ActionScript
1
star
38

js-env-run

Loads environment variables from a given ts file then executes the passed command
JavaScript
1
star
39

ExtensionServices

A generic collection of helpers and services for use in chrome extensions
TypeScript
1
star