com.alicizax.unity.framework/Runtime/ObjectPool/ObjectPoolComponent.cs

40 lines
1001 B
C#
Raw Normal View History

using AlicizaX.ObjectPool;
2025-10-11 15:18:09 +08:00
using UnityEngine;
namespace AlicizaX
{
2025-10-11 15:18:09 +08:00
public sealed class ObjectPoolComponent : MonoBehaviour
{
private IObjectPoolService _mObjectPoolService;
2025-10-11 15:18:09 +08:00
public int Count => _mObjectPoolService.Count;
2025-10-11 15:18:09 +08:00
private void Awake()
{
2026-04-20 13:46:44 +08:00
_mObjectPoolService = AppServices.RegisterApp(new ObjectPoolService());
Application.lowMemory += OnLowMemory;
2025-10-11 15:18:09 +08:00
}
private void OnDestroy()
{
Application.lowMemory -= OnLowMemory;
_mObjectPoolService = null;
2025-10-11 15:18:09 +08:00
}
private void OnLowMemory()
{
if (_mObjectPoolService is ObjectPoolService svc)
svc.OnLowMemory();
}
2026-04-23 19:09:56 +08:00
internal int GetAllObjectPools(bool sort, ObjectPoolBase[] results)
2025-10-11 15:18:09 +08:00
{
2026-04-23 19:09:56 +08:00
if (_mObjectPoolService is IObjectPoolServiceDebugView debugView)
return debugView.GetAllObjectPools(sort, results);
return 0;
2025-10-11 15:18:09 +08:00
}
}
}