-
Notifications
You must be signed in to change notification settings - Fork 0
Usage.Unity Projects
JuDelCo edited this page May 18, 2021
·
14 revisions
To use services you need to register them first. One way you can automatically register the services on runtime is creating this static class anywhere in your project, it will run before any scene so it's the perfect entry point for the services to setup:
using UnityEngine;
using Ju.Services;
public static class Bootstrap
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
private static void Init()
{
// Core services
ServiceContainer.RegisterService<ITaskService, TaskService>();
ServiceContainer.RegisterService<ICoroutineService, CoroutineService>();
ServiceContainer.RegisterService<ICacheService, CacheService>();
// Unity related services
ServiceContainer.RegisterService<ILogUnityService, LogUnityService>();
ServiceContainer.RegisterService<IInputService, InputUnityService>();
ServiceContainer.RegisterService<ITimeService, UnityTimeService>();
ServiceContainer.RegisterService<IUnityService, UnityService>();
ServiceContainer.RegisterService<IPrefabPoolService, PrefabPoolService>();
// Register your custom services here
}
}
You can rename the class and the method to whatever you want.
Read more on how to use the Service Container here.
You can register the services in your own entry point method to control whenever the services get registered like it's done in native C# projects. Just keep in mind that the UnityService
will fire all the update loop events and dispose the Service Container automatically.
Return to [Home]
- Home
- Install
- Manual
-
Core API
- Services:
- Util:
-
Unity API
- Services:
- Integrations: