36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|