Service Tag In addition to global services – which are guaranteed to be available to all clients for the entire lifetime of the application – it is also possible to register local services using Service Tags. Local services live as part of scene or prefab assets, and are only available to clients for as long ..
Author : Timo Naskali
Services that can automatically be delivered to clients by Init(args) can be split into two groups based on their availability: local and global services. A local service is a service that is only available to select clients, depending on their location in the scene hierarchies. Unlike global services, local services only exist for a limited ..
Services that can automatically be delivered to clients by Init(args) can be split into two groups based on their availability: global and local services. A global service is a service that is available to all clients, regardless of their location in the scene hierarchies. Registering Global Services The main way to register global services is ..
The [ValueProviderMenu] attribute can be used to introduce new menu items that will be shown in the dropdown menus for all Init arguments of targeted types. The attribute can be added to a ScriptableObject-derived class that implements IValueProvider<TValue> or IValueByTypeProvider. You can then use the Value property to access the value stored inside the field. ..
Add this attribute to a component to have the arguments accepted by it be automatically gathered and passed to its Init function in Edit Mode, whenever any objects in the same scene or prefab that contains the component are modified. This attribute supports any components that implement IInitializable<T>, which includes all classes that derive from ..
Opening The Service Debugger Window You can open the Service Debugger Window using the main menu item Window > Analysis > Service Debugger. Using The Service Debugger Window The window lists all currently active services, which have been registered via ServiceAttributes, Service Tags and Services Components. The first name shown in the list is the ..
Issue When launching the game, a service does not get injected to any of its clients as expected, and an warning similar to the following can be seen in the Console window: Invalid Service Definition: Class of the registered instance ‘MyService’ does not implement the defining interface type of the service ‘IMyInterface’. UnityEngine.Debug:LogWarning (object) Sisus.Init.ServiceUtility:SetInstance ..
Issue An client component does not receive the objects that it depends on in its Init method during its initialization. Cause: Not All Dependencies Are Services One possible reason for this is that the component depends on one or more objects that have not been registered as services. Components that derive from MonoBehaviour<T…> can only ..
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 ..
AddComponent with Arguments A new component that derives from MonoBehaviour<T…> or implements IArgs<T…> can be attached to GameObject and initialized with arguments using the AddComponent<TComponent, T…> extension methods in the Sisus.Init namespace. The methods work just like the built-in AddComponent<T> methods, except you also list the types of the component’s Init parameters as generic type ..