The service locator is like the singleton pattern, but better. Using it, you gain centralized access to all your services, as if they were singletons, from one place. You can also register new services or swap them at runtime. All the code for the service locator we will be writing will be generic so that you can use it with any class, including MonoBehaviours.
Like and
Subscribe for More Unity and C# Tutorials https://www.youtube.com/@UClTnTUyCeSu9tN8FNNoXMRg
Project files – https://www.patreon.com/posts/112534938
Support My Work and Unlock Exclusive Content!
Patreon: https://www.patreon.com/FreedomCoding
Join Our Developer Community!
Discord: https://discord.gg/JzssYyjvGu
Support Me Financially
PayPal: jani.steckerova@seznam.cz
Website – https://www.freedom-coding.com
Timestamps:
00:00 What Is Service Locator?
00:37 Pros And Cons
01:00 Understanding Service Locator
02:07 Service Locator Script
05:57 Service Interfaces
06:16 Concrete Services
07:05 Service Installer
10:00 Client Code
10:51 The Result
Voir sur youtube