GUIViewportScope.cs 800 B

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor
  4. {
  5. // Special Clip Scope that only effects painting, and keeps the coordinate system identical
  6. struct GUIViewportScope : IDisposable
  7. {
  8. bool m_open;
  9. public GUIViewportScope(Rect position)
  10. {
  11. m_open = false;
  12. if (Event.current.type == EventType.Repaint || Event.current.type == EventType.Layout)
  13. {
  14. GUI.BeginClip(position, -position.min, Vector2.zero, false);
  15. m_open = true;
  16. }
  17. }
  18. public void Dispose()
  19. {
  20. CloseScope();
  21. }
  22. void CloseScope()
  23. {
  24. if (m_open)
  25. {
  26. GUI.EndClip();
  27. m_open = false;
  28. }
  29. }
  30. }
  31. }