GameObjects


The gameobjects category contains several useful scripts and components that let you easily work with gameobjects and components it also contains a number of abstract / base classes for implementing common patterns and features.

Scripts

GameObjectHelper and GameObjectExtentions provide several helper methods and extension methods for accessing and working with GameObjects and Components such as selection by name and more.

MinMax and MinMaxf are helper structs for representing a range of numbers with various helper functions. They both feature a property drawer for ease of display in the Unity Editor.

Singletons

Singletons ensure that only one instance of a component will exist at a given time and give an easy means of accessing that instance (Through xxx.Instance). You can create your own Singleton classes by simply inheriting from one of the base classes (Singleton<T> or SingletonPersistant<T>). The one to chose depends upon whether they should Persist across scene changes.

All Singleton classes provide virtual GameSetup and GameDestroy methods that you should use implement (if needed) instead of Awake and OnDestroy. GameSetup and GameDestroy will only be called on the singleton that is actually setup.

Several common components in Game Framework use this pattern including GameManager, FreePrizeManager, PaymentManager etc..

Conditional Execution

There are several components that let you control how and when gameobjects are executed. A number of these serve as base classes for other standard components and can also be extended for your own use.

RunOnState can be extended to let a user specified implementation of the RunMethod function be run under certain conditions ( Awake, Start, OnEnable, Update, Periodically). For your own games this might be most useful for implementing periodic polling without having to create  quite a bit of extra code. RunOnMessage<T> is a messaging based version of that handle automatically subscribing to a message and will call RunMethod when a message of that type is received. The messaging version is preferred where applicable given it avoids the need for continued polling.

EnableDisableGameObject and EnableDisableGameObjectMessaging enable one of two gameobjects based upon a condition which is defined by implementing the IsConditionMet method in a derived class. These Components extend RunOnState / RunOnStateMessaging<T> to so you can chose when the condition should be evaluated. These are useful for setting up your game, or reacting to state changes that might occur.

RunOnce lets derived classes run a method (the abstract RunOnce) one time only. This can be useful for cases like showing a message the first time someone plays your game. A record of the method being run is stored in PlayerPrefs using the provided key. You can also specify a EnableAfterKey to chain calls so that this will only run after another instance.

EnableComponentOnce and EnableOnceGameObject use the features from RunOnce to enable a component / gameobject one time only.

AutoDestructWhenNoChildren lets you destroy or disable the gameobject when it has no children lets

See also

If you have any thoughts or suggestions on improvements or additions to the GameObject features then please let us know!