Category : 03. Features

IArgs<T…> Classes that implement one of the generic IArgs<T…> interfaces can receive one or more arguments, up to a maximum of five, during initialization. Any object that implements an IArgs<T…> interface makes a promise to receive arguments that have been injected for them during their initialization phase, using the InitArgs.TryGet method. Classes that derive from ..

Read more

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 ..

Read more

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 ..

Read more

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 ..

Read more

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, serialize it as an asset in the project. Let’s say you had a plain old class called Settings: public class Settings { } To create ..

Read more

The Wrapper class is a component that acts as a simple wrapper for a plain old class object. It makes it easy to take a plain old class 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 ..

Read more

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 ..

Read more

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 ..

Read more

A major benefit of injecting dependencies from the outside through the Init method is that it makes it easy to decouple your components from specific implementations, provided you use interfaces instead of specific classes as your argument types. The list of arguments that the Init method accepts also makes it very clear what other objects ..

Read more

The InitArgs class is the bridge through which initialization arguments are passed from the classes that create instances to the objects that are being created (called clients). Note that in most cases you don’t need to use InitArgs directly; all of the various methods Inity provides for initializing instances with arguments already handle this for ..

Read more