Enables you register and then locate global services.
From your unity project folder:
npm init
npm install TEMPLATE --save
echo Assets/packages >> .gitignore
echo Assets/packages.meta >> .gitignore
The package and all its dependencies will be installed under Assets/Plugins/packages.
In case it helps, a quick video of the above: https://youtu.be/Uss_yOiLNw8
First, any service you want to use must be registered.
The simplest way to register a service is with the [RegisterService] attribute
usingBeatThat.Services;[RegisterService]publicclassFoo{}publicclassUsesLookup{voidMyMethod(){// any service that is registered// can be looked up directlyvarfoo=Services.Require<Foo>();}}It's generally a good idea to use narrow interfaces for services to avoid tight coupling. More concretely, accessing services as interfaces makes it easier to swap the implementation, and, assuming the service interfaces are narrowly defined, also makes it much easier to understand at a glance what your service-dependent code really depends upon. This can be a big time saver when you're refactoring and using tools like 'Find References' to try to go through all the classes that depend on some service.
The [RegisterService] attribute provides a couple of features to make it easier to use interfaces.
usingBeatThat.Services;publicinterfaceBar{}[RegisterService]publicclassFoo:Bar{}publicclassUsesBar{voidGetBar(){Barbar=Services.Require<Bar>();// returns instance of Foo}}usingBeatThat.Services;publicinterfaceBar{}publicclassFooBase:Bar{}[RegisterService(// interface Bar will not be auto registered// because it is not defined directly on class FooproxyInterfaces:newSystem.Type[]{typeof(Bar)})]publicclassFoo:FooBase{}publicclassUsesBar{voidGetBar(){Barbar=Services.Require<Bar>();// returns instance of Foo}}usingBeatThat.Services;publicinterfaceBar{}publicclassFooBase:Bar{}[RegisterService(// register all interfaces on class and parentsinterfaceRegistrationPolicy:InterfaceRegistrationPolicy.RegisterInterfacesDeclaredOnTypeAndParents)]publicclassFoo:FooBase{}publicclassUsesBar:DependencyInjectedBehaviour{voidGetBar(){Barbar=Services.Require<Bar>();// returns instance of Foo}}