Example-Code / ObjectPooler / ObjectPoolItem.cs
ObjectPoolItem.cs
Raw
using System.Collections.Generic;
using UnityEngine;
using static CCG.Bigfoot.StateMachine.ScreenStateMachine;
using static CCG.Bigfoot.Utility.ObjectPooler;
namespace CCG.Bigfoot.Utility
{
    /// <summary>
    /// Summary of ObjectPoolItem
    /// </summary>
    /// <remarks>
    /// Authors: CS
    /// Created: 2024-02-13
    /// </remarks>
    [System.Serializable]
    public class ObjectPoolItem
    {
        [HideInInspector]
        public Transform objectPoolName;    //--Set automatically depending on the asset name, must be public

        [Header("Select the name of the object you're pooling.")]
        [Tooltip("Go into this script and make a name that matches your item if it's not here.")]
        public PooledPrefabName prefabName; //--user drops into inspector

        [Header("How many copies to make of this prefab?")]
        public int amountToPool;            //--user drops into inspector

        [Header("Drop the prefab you want to clone here.")]
        public GameObject objectToPool;     //--user drops into inspector

        [Header("Advanced options:")]

        [Tooltip("Can the list of clones expand? Or is there a hard cap?")]
        public bool canExpand = true;

        [Tooltip("Set true to mark individul clones of this item as eligible to be marked as in use, even if they are inactive.")]
        public bool CanClonesBeInUseEvenIfInactive;

        [Tooltip("Set true to enable the auto-cleanup feature. It will Destroy() clones and remove the ObjectPoolItem if a new scene activates that isn't in the IncludedScenes list, if the list is populated.")]
        public bool IsEnableAutoCleanupClones;

        [Tooltip("Add all scenes where these clones are needed. ObjectPooler will Destroy() all clones if a scene not included in this list activates. Valid only if IsEnableAutoCleanupClones is true.")]
        public List<EScreenState> IncludedScenes;

        [Header("Parent object options:")]

        [Tooltip("Set the parent object - that holds these clones - position.")]
        public Vector3 parentPosition;

        [Tooltip("Set the parent object - that holds these clones - rotation.")]
        public Quaternion parentRotation;

        [Tooltip("Set the parent of the parent object that holds these clones. One will be created if you don't need to supply this.")]
        public Transform parent;

        /// <summary>
        /// Gets or sets a value indicating whether this item needs to remake its clones upon entering a scene not in the IncludedScenes list.
        /// Valid only if IsEnableAutoCleanupClones is true.
        /// </summary>
        public bool IsNeedsRefill{get; set;}

        /// <summary>
        /// Gets or sets a value indicating whether items of this type have ever existed. Should only be set when an item of this type is instantiated.
        /// </summary>
        public bool HasExisted { get; set; }
    }
}