Author : Timo Naskali

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

Read more

Wrappers can be used to attach plain old C# objects to a GameObjects, have them receive callbacks during Unity events like Update and OnDestroy, and to start coroutines. Creating a Wrapper Let’s say you had a plain old C# class called Player: using System; using UnityEngine; [Serializable] public class Player { [SerializeField] private Id id; ..

Read more

To fully grasp the advantages that Init(args) can unlock, it’s essential to first understand a key design principle in software engineering: inversion of control. In a nutshell, inversion of control means that instead of classes independently retrieving the objects they need, those objects are provided to them by other classes. This approach comes with several ..

Read more

When a component that derives from MonoBehaviour<T> and has the InitOnResetAttribute is first attached 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<TValue> type can be used to create serialized fields into which you can assign any objects of the given type using the Inspector. The value can be of any type which Unity can serialize, using [SerializeField] or [SerializeReference], including: Plain-old C# class UnityEngine.Object An interface type You’ll be able to select any assignable value ..

Read more

What Are Initializers? Attaching an initializer to a client component gives you the ability to customize all its Init arguments using the Inspector window – with a lot of enhancements over what’s possible using Unity’s serialized fields by default. While registering global and local services makes it convenient to deliver the same service object to ..

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 provided for initializing instances with arguments already handle this for you ..

Read more

Init(args) contains new generic versions of the ScriptableObject base class, extending it with the ability to specify upto six objects that the class depends on. For example the following GameEvent class depends on a string and a GameObject. public class GameEvent : ScriptableObject<string, GameObject> When you create a class that inherits from one of the ..

Read more

The project comes with a simple demo game showcasing many of the features offered by Init(args). It acts as an example of a very flexible and easily unit-testable architecture that can scale well to drive large projects as well. Installing Dependencies Before installing the demo game you must first install the Unity UI and Test ..

Read more

To reference code in Init(args) from your own code you need to create assembly definition assets in the roots of your script folders and add references to the assemblies containing the scripts you want to use. Init(args) contains three assemblies: InitArgs – The main assembly that contains most classes including MonoBehaviour<T…>. InitArgs.Services – This contains ..

Read more