using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Reflection; namespace WildAttack { /// /// 单例基类 /// /// public class Singleton : ISingletonExpand where T : Singleton, new() { private static T instance; public static T GetInstance() { if (instance == null) { instance = new T(); SingletonManager.singletons.Add(instance); } return instance; } public void ClearSingleton() { if (instance == this) { instance = null; } } } public interface ISingletonExpand { void ClearSingleton(); } public class SingletonManager { public static HashSet singletons = new(); public static void Clear() { foreach (var item in singletons) { item.ClearSingleton(); } singletons.Clear(); } } }