Skip to content

DatLycan/Unity-ServiceSystem

Repository files navigation

Unity C# Service System

Status GitHub Issues License


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.

📝 Table of Contents

🏁 Getting Started

Installing

  1. Install the Git Dependency Resolver.
  2. Import it in Unity with the Unity Package Manager using this URL:
    https://github.com/DatLycan/Unity-ServiceSystem.git

📦 Documentation

ServiceHandler API

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.

🎈 Usage

Implementing a 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");
 }

Managing a Service

 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>();
    }
 }

🎉 Acknowledgements

About

Service System framework for Unity

Resources

License

Stars

Watchers

Forks

Languages