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

40 lines
1001 B
C#

using AlicizaX.ObjectPool;
using UnityEngine;
namespace AlicizaX
{
public sealed class ObjectPoolComponent : MonoBehaviour
{
private IObjectPoolService _mObjectPoolService;
public int Count => _mObjectPoolService.Count;
private void Awake()
{
_mObjectPoolService = AppServices.RegisterApp(new ObjectPoolService());
Application.lowMemory += OnLowMemory;
}
private void OnDestroy()
{
Application.lowMemory -= OnLowMemory;
_mObjectPoolService = null;
}
private void OnLowMemory()
{
if (_mObjectPoolService is ObjectPoolService svc)
svc.OnLowMemory();
}
internal int GetAllObjectPools(bool sort, ObjectPoolBase[] results)
{
if (_mObjectPoolService is IObjectPoolServiceDebugView debugView)
return debugView.GetAllObjectPools(sort, results);
return 0;
}
}
}