Category : 03. Getting Started

Service Injection 101 Here is a quick showcase of how easily a service can be injected to a component: Service.cs: using Sisus.Init; using UnityEngine; [Service] class Service { public void Greet() => Debug.Log(“Hello, World!”); } Client.cs: using Sisus.Init; class Client : MonoBehaviour<Service> { protected override void Init(Service service) => service.Greet(); } You can test the ..

Read more

AddComponent with Arguments A new component that derives from MonoBehaviour<T…> or implements IInitializable<T…> can be attached to GameObject and initialized with arguments using the AddComponent<TComponent, T…> extension methods. The methods work like the built-in AddComponent<T> methods, except they allow you to also pass in Init arguments: using Sisus.Init; using UnityEngine; public static class GameManager { ..

Read more

What Is Dependency Injection Creating new components using the base classes in Init(args) is very similar to how it would work normally in Unity. The key difference is how the component obtains references to other objects that it depends on (its dependencies). Instead of components manually retrieving their dependencies using various methods like GameObject.Find, FindObjectOfType, ..

Read more