添加对象池并更新KeySettingManager的README

This commit is contained in:
2024-07-10 16:39:46 +08:00
parent 68665845ab
commit 15c2849090
5 changed files with 187 additions and 10 deletions

View 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 + " 单例实力已创建");
}
}
}
}