A game about forced loneliness, made by TACStudios
at master 35 lines 934 B view raw
1using System; 2using System.Collections.Generic; 3using UnityEngine.Pool; 4 5namespace UnityEngine.Experimental.Rendering 6{ 7 internal class XRLayoutStack : IDisposable 8 { 9 readonly Stack<XRLayout> m_Stack = new (); 10 11 public XRLayout New() 12 { 13 GenericPool<XRLayout>.Get(out var layout); 14 m_Stack.Push(layout); 15 return layout; 16 } 17 18 public XRLayout top => m_Stack.Peek(); 19 20 public void Release() 21 { 22 if (!m_Stack.TryPop(out var value)) 23 throw new InvalidOperationException($"Calling {nameof(Release)} without calling {nameof(New)} first."); 24 25 value.Clear(); 26 GenericPool<XRLayout>.Release(value); 27 } 28 29 public void Dispose() 30 { 31 if (m_Stack.Count != 0) 32 throw new Exception($"Stack is not empty. Did you skip a call to {nameof(Release)}?"); 33 } 34 } 35}