-
Notifications
You must be signed in to change notification settings - Fork 0
Usage.Getting Started
You can use this package as it is in native C# applications, it will work just fine (all Unity-related code is enclosed using preprocessor directives).
Important: How to manage the lifecycle of the Service Container in native C# applications.
Add the following git URL in the package manager of your project:
https://github.com/JuDelCo/Core.git#v1.43.0
If you keep the version in the URL, Unity will download always that version even if there are new versions of this repository so you can work in a stable environment.
Please note that the minimum version supported is Unity 2019.3 or later (it won't work in older versions).
Important: Follow this steps to finish the setup of your Unity project.
You can create a static class in your project to improve your experience with the services you use more frequently.
Note: Consider caching the service references in a private variable if you need to use the service a lot in one class.
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 related services
// Note: Comment out if you are using Unity
//public static ITimeService Time => ServiceContainer.Get<ITimeService>();
//public static IUnityService Unity => ServiceContainer.Get<IUnityService>();
//public static IInputService Input => ServiceContainer.Get<IInputService>();
//public static IPrefabPoolService Pool => ServiceContainer.Get<IPrefabPoolService>();
// ... 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 ...
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: