WXMC/proj/unity/Assets/Scripts/Message/DataSingleton.cs
2024-12-04 16:18:46 +08:00

35 lines
671 B
C#

using System;
public abstract class DataSingleton<T> where T : class, new()
{
private static T m_instance;
public static T Instance
{
get
{
if (DataSingleton<T>.m_instance == null)
{
DataSingleton<T>.m_instance = Activator.CreateInstance<T>();
if (DataSingleton<T>.m_instance != null)
{
(DataSingleton<T>.m_instance as DataSingleton<T>).Init();
}
}
return DataSingleton<T>.m_instance;
}
}
public static void Release()
{
if (DataSingleton<T>.m_instance != null)
{
DataSingleton<T>.m_instance = (T) ((object) null);
}
}
public void Startup()
{
}
public abstract void Init();
public abstract void OnDispose();
}