-
Notifications
You must be signed in to change notification settings - Fork 1
Usage.Getting Started
You can use this package as it is in Unity, Godot and native C# applications, it will work just fine. All Unity/Godot-related code is enclosed using preprocessor directives.
First, follow the instructions for your specific case:
After the installation, you can create a static class in your project to improve your experience with the services you use more frequently:
using Ju.Services;
public static class Core
{
// Methods to get services from the service container
public static T Get<T>() => ServiceContainer.Get<T>();
public static T Get<T>(string id) => ServiceContainer.Get<T>(id);
// Core services
public static IEventBusService Event => ServiceContainer.Get<IEventBusService>();
public static ITaskService Task => ServiceContainer.Get<ITaskService>();
public static ICoroutineService Coroutine => ServiceContainer.Get<ICoroutineService>();
public static ICacheService Cache => ServiceContainer.Get<ICacheService>();
// Unity/Godot related services
// Note: Comment out if you are using Unity/Godot
//public static ITimeService Time => ServiceContainer.Get<ITimeService>();
//public static IUnityService Unity => ServiceContainer.Get<IUnityService>(); // Unity-specific
//public static IUnityService Godot => ServiceContainer.Get<IGodotService>(); // Godot-specific
//public static IInputService Input => ServiceContainer.Get<IInputService>();
//public static IPrefabPoolService Pool => ServiceContainer.Get<IPrefabPoolService>(); // Unity-specific
//public static INodePoolService Pool => ServiceContainer.Get<INodePoolService>(); // Godot-specific
// ... add more shorthands as you need
}
Now you can use anywhere a static class named Core
(you can name it as you like) to use more easily your services or custom shorthand methods:
// Fire damage event
Core.Event.Fire<DamageEvent>();
// Check if Space key is held
Core.Input.Keyboard.IsKeyHeld(KeyboardKey.Space);
// etc ...
Note: Consider caching the service references in a private variable if you need to use the service a lot in one class.
Read how to use the Service Container and how to create your own Services.
After that, read about the Update Loop Events you can use, how to do logging and what LinkHandlers are.
Return to [Home]
- Home
- Install
- Manual
-
Core API
- Services:
- Util:
-
Unity API
- Services:
- Integrations: