This commit is contained in:
2024-10-16 00:03:41 +08:00
commit 897058435c
5033 changed files with 1009728 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
using UnityEngine;
namespace IcecreamView
{
/// <summary>
/// 单例模板类
/// </summary>
/// <typeparam name="T">必须为继承MonoBehaviour对象</typeparam>
public class SingletonTemplate<T> : MonoBehaviour where T : MonoBehaviour
{
private static volatile T instance;
private static object syncRoot = new Object();
public static T Instance
{
get
{
lock (syncRoot)
{
if (instance == null)
{
instance = FindObjectOfType<T>();
if (instance == null)
{
GameObject go = new GameObject();
go.name = typeof(T).Name;
instance = go.AddComponent<T>();
}
}
}
return instance;
}
}
}
}