【m】11.PointCloudTools 上传
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Main;
|
||||
using UnityEngine;
|
||||
|
||||
public static class PointCloudService
|
||||
{
|
||||
private static readonly Dictionary<Type, object> Services = new Dictionary<Type, object>();
|
||||
|
||||
static PointCloudService()
|
||||
{
|
||||
Services.Clear();
|
||||
|
||||
}
|
||||
public static void RegisterService<T>(T service)
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (Services.ContainsKey(type))
|
||||
{
|
||||
Services[type] = service;
|
||||
}
|
||||
else
|
||||
{
|
||||
Services.Add(type, service);
|
||||
}
|
||||
}
|
||||
|
||||
public static T GetService<T>()
|
||||
{
|
||||
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<T>()
|
||||
{
|
||||
var type = typeof(T);
|
||||
if (Services.ContainsKey(type))
|
||||
{
|
||||
Services.Remove(type);
|
||||
}
|
||||
}
|
||||
public static void ClearServices()
|
||||
{
|
||||
Services.Clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user