36 lines
1.0 KiB
C#
Raw Normal View History

2025-01-02 12:15:45 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*******************************************************************************
*Create By CG
*Function
*******************************************************************************/
namespace CG.Framework
{
public class ClassSingleton<T> where T : ClassSingleton<T>
{
private volatile static T _instance = null;
protected ClassSingleton() { }
private static readonly object sysObj = new object();
public static T Instance
{
get
{//懒汉式
if (_instance == null)
{
lock (sysObj)
{
if (_instance == null)
{
_instance = System.Activator.CreateInstance(typeof(T), true) as T;
}
}
}
return _instance;
}
}
}
}