Service System framework for managing and controlling various services, providing functionalities to start, stop, pause, locate, and update services, as well as manage their lifecycle.
- Install the Git Dependency Resolver.
- Import it in Unity with the Unity Package Manager using this URL:
https://github.com/DatLycan/Unity-ServiceSystem.git
Declaration | Returns | Description |
---|---|---|
Register | void | Registers a specified service. |
Unregister | void | Unregisters a specified service. |
Start | void | Starts a specified service. |
Stop | void | Stops a specified service. |
Pause | void | Pauses (or resumes) a specified service. |
Locate | IService | Locates and returns the specified service instance. |
TryGetStatus | bool | Tries to get the status of the specified service. |
public class MyService : IService {
public Priority GetPriority() => Priority.VeryHigh;
public bool DoAutoStart() => true;
public void OnStart() => Debug.Log("MyService Start");
public void OnStop() => Debug.Log("MyService Stopped");
public void Update() => Debug.Log("MyService Update");
}
public class MyClass {
private void MyMethod() {
if (!ServiceHandler.TryGetStatus(out MyService serviceInstance, out bool isRunning, out bool hasStarted, out bool hasStopped)) return;
Debug.Log($"Instance: {serviceInstance} | IsRunning: {isRunning} | HasStarted: {hasStarted} | HasStopped: {hasStopped}");
Debug.Log($"Priority: {ServiceHandler.Locate<MyService>().GetPriority()}");
ServiceHandler.Pause<MyService>(true);
ServiceHandler.Pause<MyService>(false);
ServiceHandler.Stop<MyService>();
ServiceHandler.Start<MyService>();
ServiceHandler.Unregister<MyService>();
ServiceHandler.Register<MyService>();
ServiceHandler.Start<MyService>();
}
}