using System; namespace UnityEngine.XR.Interaction.Toolkit.Utilities.Pooling { // Class based on UnityEngine.Pool.PooledObject, which was added to Unity 2021.1. // When the minimum Editor dependency is bumped, replace use of this internal struct. /// /// A Pooled object wraps a reference to an instance that will be returned to the pool when the Pooled object is disposed. /// The purpose is to automate the return of references so that they do not need to be returned manually. /// A PooledObject can be used like so: /// /// MyClass myInstance; /// using (myPool.Get(out myInstance)) // When leaving the scope myInstance will be returned to the pool. /// { /// // Do something with myInstance /// } /// /// readonly struct PooledObject : IDisposable where T : class { readonly T m_ToReturn; readonly LinkedPool m_Pool; internal PooledObject(T value, LinkedPool pool) { m_ToReturn = value; m_Pool = pool; } void IDisposable.Dispose() => m_Pool.Release(m_ToReturn); } }