com.alicizax.unity.framework/Runtime/ABase/ObjectPool/ObjectBase.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2025-10-11 15:18:09 +08:00
namespace AlicizaX.ObjectPool
{
public abstract class ObjectBase : IMemory
{
private string m_Name;
private object m_Target;
private bool m_Locked;
private float m_LastUseTime;
2025-10-11 15:18:09 +08:00
public string Name => m_Name;
public object Target => m_Target;
2025-10-11 15:18:09 +08:00
public bool Locked
{
get => m_Locked;
set => m_Locked = value;
2025-10-11 15:18:09 +08:00
}
public float LastUseTime
2025-10-11 15:18:09 +08:00
{
get => m_LastUseTime;
internal set => m_LastUseTime = value;
2025-10-11 15:18:09 +08:00
}
public virtual bool CustomCanReleaseFlag => true;
2025-10-11 15:18:09 +08:00
protected void Initialize(object target)
{
Initialize(string.Empty, target, false);
2025-10-11 15:18:09 +08:00
}
protected void Initialize(string name, object target)
{
Initialize(name, target, false);
2025-10-11 15:18:09 +08:00
}
protected void Initialize(string name, object target, bool locked)
{
m_Name = name ?? string.Empty;
m_Target = target;
m_Locked = locked;
m_LastUseTime = 0f;
2025-10-11 15:18:09 +08:00
}
protected internal virtual void OnSpawn() { }
protected internal virtual void OnUnspawn() { }
protected internal abstract void Release(bool isShutdown);
2025-10-11 15:18:09 +08:00
public virtual void Clear()
{
m_Name = null;
m_Target = null;
m_Locked = false;
m_LastUseTime = 0f;
2025-10-11 15:18:09 +08:00
}
}
}