To test our implementation of the Service Locator pattern, let's write a client class that we will attach as a component to a GameObject in an empty Unity scene, as follows:
using UnityEngine;
namespace Chapter.ServiceLocator
{
public class ClientServiceLocator : MonoBehaviour
{
void Start() {
RegisterServices();
}
private void RegisterServices() {
ILoggerService logger = new Logger();
ServiceLocator.RegisterService(logger);
IAnalyticsService analytics = new Analytics();
ServiceLocator.RegisterService(analytics);
IAdvertisement advertisement = new Advertisement();
ServiceLocator.RegisterService(advertisement);
}
void OnGUI()
{
GUILayout.Label("Review output in the console:");
if (GUILayout.Button("Log Event")) {
ILoggerService logger =
ServiceLocator...