架构大更
This commit is contained in:
@@ -4,67 +4,66 @@ using UnityEngine.Events;
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this class to an object that you expect to pool from an objectPooler.
|
||||
/// Note that these objects can't be destroyed by calling Destroy(), they'll just be set inactive (that's the whole point).
|
||||
/// Add this class to an object that you expect to pool from an objectPooler.
|
||||
/// Note that these objects can't be destroyed by calling Destroy(), they'll just be set inactive (that's the whole
|
||||
/// point).
|
||||
/// </summary>
|
||||
[AddComponentMenu("More Mountains/Tools/Object Pool/MM Poolable Object")]
|
||||
public class MMPoolableObject : MMObjectBounds
|
||||
{
|
||||
[Header("Events")]
|
||||
public UnityEvent ExecuteOnEnable;
|
||||
public UnityEvent ExecuteOnDisable;
|
||||
|
||||
public delegate void Events();
|
||||
public event Events OnSpawnComplete;
|
||||
public class MMPoolableObject : MMObjectBounds
|
||||
{
|
||||
public delegate void Events();
|
||||
|
||||
[Header("Poolable Object")]
|
||||
/// The life time, in seconds, of the object. If set to 0 it'll live forever, if set to any positive value it'll be set inactive after that time.
|
||||
public float LifeTime = 0f;
|
||||
[Header("Events")] public UnityEvent ExecuteOnEnable;
|
||||
|
||||
/// <summary>
|
||||
/// Turns the instance inactive, in order to eventually reuse it.
|
||||
/// </summary>
|
||||
public virtual void Destroy()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
public UnityEvent ExecuteOnDisable;
|
||||
|
||||
/// <summary>
|
||||
/// Called every frame
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
[Header("Poolable Object")]
|
||||
/// The life time, in seconds, of the object. If set to 0 it'll live forever, if set to any positive value it'll be set inactive after that time.
|
||||
public float LifeTime;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Called every frame
|
||||
/// </summary>
|
||||
protected virtual void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the objects get enabled (usually after having been pooled from an ObjectPooler, we initiate its death countdown.
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
Size = GetBounds().extents * 2;
|
||||
if (LifeTime > 0f)
|
||||
{
|
||||
Invoke("Destroy", LifeTime);
|
||||
}
|
||||
ExecuteOnEnable?.Invoke();
|
||||
}
|
||||
/// <summary>
|
||||
/// When the objects get enabled (usually after having been pooled from an ObjectPooler, we initiate its death
|
||||
/// countdown.
|
||||
/// </summary>
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
Size = GetBounds().extents * 2;
|
||||
if (LifeTime > 0f) Invoke("Destroy", LifeTime);
|
||||
ExecuteOnEnable?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When the object gets disabled (maybe it got out of bounds), we cancel its programmed death
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
ExecuteOnDisable?.Invoke();
|
||||
CancelInvoke();
|
||||
}
|
||||
/// <summary>
|
||||
/// When the object gets disabled (maybe it got out of bounds), we cancel its programmed death
|
||||
/// </summary>
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
ExecuteOnDisable?.Invoke();
|
||||
CancelInvoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the on spawn complete event
|
||||
/// </summary>
|
||||
public virtual void TriggerOnSpawnComplete()
|
||||
{
|
||||
OnSpawnComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
public event Events OnSpawnComplete;
|
||||
|
||||
/// <summary>
|
||||
/// Turns the instance inactive, in order to eventually reuse it.
|
||||
/// </summary>
|
||||
public virtual void Destroy()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Triggers the on spawn complete event
|
||||
/// </summary>
|
||||
public virtual void TriggerOnSpawnComplete()
|
||||
{
|
||||
OnSpawnComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user