using UnityEngine; using System.Collections.Generic; using System; public class Services : SingletonPersistentMonoBehaviour { Dictionary m_services = new Dictionary(); protected override void OnAwake () { MonoBehaviour[] services = GetComponentsInChildren(); for(int i=0; i() where U : class { if(m_destroyed) { Debug.LogWarning("Services: Calling Get when the object has already been destroyed."); return null; } Type type = typeof(U); if( Instance.m_services.ContainsKey(type) ) { return Instance.m_services[type] as U; } return null; } public static void Set(U service) where U : class { if(m_destroyed) { Debug.LogWarning("Services: Calling Set when the object has already been destroyed."); return; } Type type = service.GetType(); Instance.m_services[type] = service; } }