Init(args) contains new generic versions of the StateMachineBehaviour base class, extending it with the ability to receive up to six objects during initialization. For example the following AttackBehaviour class depends on an object that implements the IAttackable interface and a ScriptableObject asset of type AttackBehaviourSettings: public class AttackBehaviour : StateMachineBehaviour<IAttackable, AttackBehaviourSettings> When you create a ..
Category : 04. Features
Init(args) has been designed with inversion of control in mind and aims to make it as easy as possible to work with interfaces instead of specific classes in Unity. One pain point when using interfaces in Unity is that checking them for null can be problematic. This is because in addition to being actually null, ..
A base class for MonoBehaviours that depend on receiving upto six objects in their constructor during initialization. For example the following Player class depends on an object that implements the IInputManager interface and an object of type Camera. public class Player : ConstructorBehaviour<IInputManager, Camera> When you create a component that inherits from one of the ..
Sometimes you may want to make use of read-only fields or get-only properties in your components and scriptable objects. Read-only members make your data immutable and as such result in code that is less prone to errors and fully thread safe without needing any complicated thread locking. The issue is that you can’t pass any ..
The generic GameObject structs are builder that can be used to initialize a GameObject and upto three components in a single line of code. If you want a GameObject with a single component to be build, initialize a new instance of the GameObject<T> struct and specify the type of the component you want attached to ..
The Find class is a utility class that helps in locating instances of objects from loaded scenes as well as assets from the project. It has been designed from the ground up to work well with interface types, making it easier to decouple your code from specific concrete classes. All methods in the Find class ..
The ScriptableWrapper class is a ScriptableObject that can act as a simple wrapper for a plain old class object. It makes it easy to take a plain old class object and serialize it as an asset in the project. Let’s say you had a plain old class called Settings: public class Settings { public float ..
The Wrapper class is a component that acts as a simple wrapper for a plain old C# object. It makes it easy to take a plain old C# object and attach it to a GameObject and have it receive callbacks during any Unity events you care about such as Update or OnDestroy as well as ..
When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first added to a GameObject in the editor, or when the user hits the Reset button in the Inspector’s context menu, the arguments accepted by the component are automatically gathered and passed to its Init function. This auto-initialization behaviour only occurs in edit ..
The Any<T> struct is similar to the Initializer class, but instead of it allowing you to specify all the Init arguments for a client, the Any<T> struct lets you specify just one argument. For example, if you wanted to make it possible to assign any class that implements the IPlayer interface using the inspector, you ..