using System; namespace XGame.Framework { public class TSingleton where TType : TSingleton, new() { private static TType _instance; public static void Dispose() { _instance?.OnDispose(); _instance = null; } public static TType Instance { get { if (_instance == null) { _instance = Activator.CreateInstance(); _instance.OnInit(); } return _instance; } } protected virtual void OnInit() { } protected virtual void OnDispose() { } } }