添加对象池并更新KeySettingManager的README
This commit is contained in:
29
Pool/Editor/SingletonObjectPoolerInitializer.cs
Normal file
29
Pool/Editor/SingletonObjectPoolerInitializer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AnnoyingUtils.Pool.Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public static class SingletonObjectPoolInitializer
|
||||
{
|
||||
static SingletonObjectPoolInitializer()
|
||||
{
|
||||
CreateSingletonInstances();
|
||||
}
|
||||
|
||||
private static void CreateSingletonInstances()
|
||||
{
|
||||
var types = typeof(SingletonObjectPool<>).Assembly.GetTypes();
|
||||
foreach (var type in types)
|
||||
{
|
||||
if (!type.IsSubclassOf(typeof(MonoBehaviour)) || !type.BaseType.IsGenericType ||
|
||||
type.BaseType.GetGenericTypeDefinition() != typeof(SingletonObjectPool<>)) continue;
|
||||
var existingInstances = UnityEngine.Object.FindObjectsOfType(type);
|
||||
if (existingInstances.Length != 0) continue;
|
||||
var obj = new GameObject(type.Name);
|
||||
obj.AddComponent(type);
|
||||
Debug.Log(type.Name + " 单例实力已创建");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user