-
Book Overview & Buying
-
Table Of Contents
Learning Design Patterns with Unity
By :
Even though the foundation of the Service Locator pattern isn’t as complicated as some of the other systems we’ve tackled throughout our journey, it’s important to think about extended features that add to its usability, which we’ll do in this last section.
As far as automatically registering or initializing your services before a client needs them, Unity has a wonderful set of callbacks that can be invoked at different points in the runtime startup. All we need is a static method, the RuntimeInitializeLoadMethod attribute, and a selected RuntimeInitializeLoadType.
In the Scripts folder, create a new C# script named ServiceBootstrapper and update its contents to match the following code block:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// 1
public static class ServiceBootstrapper
{
// 2
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType...