#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.GameObjectTasks { using System.Collections.Generic; using UnityEngine; using UnityEngine.Pool; /// /// Singleton manager that tracks which pool each GameObject belongs to. /// public class PoolManager { private static PoolManager s_Instance; private Dictionary> m_PoolMap = new Dictionary>(); /// /// Gets the singleton instance. /// public static PoolManager Instance { get { if (s_Instance == null) { s_Instance = new PoolManager(); } return s_Instance; } } /// /// Registers a GameObject with its pool. /// /// The GameObject to register. /// The pool that the GameObject belongs to. public void Register(GameObject obj, ObjectPool pool) { if (obj != null && pool != null) { m_PoolMap[obj] = pool; } } /// /// Unregisters a GameObject from the pool manager. /// /// The GameObject to unregister. public void Unregister(GameObject obj) { if (obj != null) { m_PoolMap.Remove(obj); } } /// /// Releases a GameObject back to its pool. /// /// The GameObject to release. /// True if the object was released to a pool, false otherwise. public bool ReleaseToPool(GameObject obj) { if (obj != null && m_PoolMap.TryGetValue(obj, out var pool)) { pool.Release(obj); return true; } return false; } /// /// Gets the pool for a GameObject. /// /// The GameObject to get the pool for. /// The pool, or null if not found. public ObjectPool GetPool(GameObject obj) { if (obj != null && m_PoolMap.TryGetValue(obj, out var pool)) { return pool; } return null; } /// /// Clears all registered pools. /// public void Clear() { m_PoolMap.Clear(); } } } #endif