neuro-machina / FService

Simple service pattern plugin for Flax Engine, inspired by MonoGame ServiceContainer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FService

Simple service pattern plugin for Flax Engine, inspired by MonoGame ServiceContainer.

To incorportate the plugin to your flax project, simply add the two cs files (IServicePlugin.cs and ServicePlugin.cs ) anywhere in your project, or simply copy paste the code directly in new created cs files in your source project.

How to use:

First you need to register a service, it can be done from anywhere you want as long you are registering a class, can also register an object by interface:

using FService;

ServicePlugin.Instance.AddService<MyServiceType>(MyServiceObject);

Then to retrieve a service simply call:

ServicePlugin.Instance.GetService<MyServiceType>();

You can also remove services (usefull for script type to be cleared on OnDestroy):

ServicePlugin.Instance.RemoveService(typeof(MyServiceType));

There are also two event Action callbacks you can subscribe to in the plugin for when a service is added and removed:

ServicePlugin.Instance.Add += MyVoidMethod;
ServicePlugin.Instance.Remove += MyVoidMethod;

Notes:

This is pretty much the ServiceContainer from MonoGame project, just wrapped up for Flax Engine use.

About

Simple service pattern plugin for Flax Engine, inspired by MonoGame ServiceContainer.


Languages

Language:C# 100.0%