Example-Code / ObjectPooler / IPoolable.cs
IPoolable.cs
Raw
#nullable enable
using UnityEngine;
using static CCG.Bigfoot.Utility.ObjectPooler;

namespace CCG.Bigfoot.Utility
{
    /// <summary>
    /// Expand your MonoBehavior with IPoolable if it's in the ObjectPooler.
    /// </summary>
    /// <remarks>
    /// Authors: CS
    /// Created: 2024-01-09
    /// </remarks>
    public interface IPoolable
    {
        /// <summary>
        /// Identifies this object. Set by ObjectPooler. Don't change unless you know what you're doing.
        /// </summary>
        PooledPrefabName Identifier { get; set; }

        /// <summary>
        /// This will affect ObjectPooler so they'll only pull out clones of an item type that are inactive AND !IsInUseEvenIfInactive
        /// </summary>
        bool IsInUseEvenIfInactive { get; set; }

        /// <summary>
        /// You can cahce the Mono that implements this.
        /// </summary>
        MonoBehaviour? Mono { get; set; }

        /// <summary>
        /// Activates the poolable object. Call after you Get() an item out of the pool.
        /// </summary>
        void Activate();

        /// <summary>
        /// Prepare to Activate() your clone here using a ScriptableObject.
        /// </summary>
        void Setup(ScriptableObject data);

        /// <summary>
        /// Deactivates the poolable object. Call after you're done using the item to recycle it back into the pool. Remember to wash any data before calling this.
        /// </summary>
        void Deactivate(bool isReturnToPoolAfterDeactivate);

        /// <summary>
        /// Add gameObject.SetActive(isActive)
        /// </summary>
        /// <param name="isActive"></param>
        void SetActive(bool isActive);
    }
}