暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XRLayoutStack.cs 934B

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