using System; using System.Collections; using System.Collections.Generic; using Main; using UnityEngine; public static class PointCloudService { private static readonly Dictionary Services = new Dictionary(); static PointCloudService() { Services.Clear(); } public static void RegisterService(T service) { var type = typeof(T); if (Services.ContainsKey(type)) { Services[type] = service; } else { Services.Add(type, service); } } public static T GetService() { var type = typeof(T); if (Services.TryGetValue(type, out var service)) { return (T)service; } else { // 抛出异常或返回空服务 throw new Exception($"Service of type 【{type}】 not found, please check if the service is registered."); } } public static void UnregisterService() { var type = typeof(T); if (Services.ContainsKey(type)) { Services.Remove(type); } } public static void ClearServices() { Services.Clear(); } }