暫無描述
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.

DebugOverlay.cs 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. namespace UnityEngine.Rendering
  2. {
  3. /// <summary>
  4. /// Utility class for debug overlay coordinates.
  5. /// </summary>
  6. public class DebugOverlay
  7. {
  8. /// <summary>Current x coordinate.</summary>
  9. public int x { get; private set; }
  10. /// <summary>Current y coordinate.</summary>
  11. public int y { get; private set; }
  12. /// <summary>Current overlay size.</summary>
  13. public int overlaySize { get; private set; }
  14. int m_InitialPositionX;
  15. int m_ScreenWidth;
  16. /// <summary>
  17. /// Start rendering overlay.
  18. /// </summary>
  19. /// <param name="initialX">Initial x position.</param>
  20. /// <param name="initialY">Initial y position.</param>
  21. /// <param name="overlaySize">Size of overlays between 0 and 1.</param>
  22. /// <param name="screenWidth">Width of the screen.</param>
  23. public void StartOverlay(int initialX, int initialY, int overlaySize, int screenWidth)
  24. {
  25. x = initialX;
  26. y = initialY;
  27. this.overlaySize = overlaySize;
  28. m_InitialPositionX = initialX;
  29. m_ScreenWidth = screenWidth;
  30. }
  31. /// <summary>
  32. /// Increment coordinates to the next overlay and return the current overlay rect.
  33. /// </summary>
  34. /// <param name="aspect">Aspect of the current overlay.</param>
  35. /// <returns>Returns a rect of the current overlay.</returns>
  36. public Rect Next(float aspect = 1.0f)
  37. {
  38. int overlayWidth = (int)(overlaySize * aspect);
  39. if ((x + overlayWidth) > m_ScreenWidth && x > m_InitialPositionX)
  40. {
  41. x = m_InitialPositionX;
  42. y -= overlaySize;
  43. }
  44. Rect rect = new Rect(x, y, overlayWidth, overlaySize);
  45. x += overlayWidth;
  46. return rect;
  47. }
  48. /// <summary>
  49. /// Setup the viewport for the current overlay.
  50. /// </summary>
  51. /// <param name="cmd">Command buffer used to setup viewport.</param>
  52. public void SetViewport(CommandBuffer cmd)
  53. {
  54. cmd.SetViewport(new Rect(x, y, overlaySize, overlaySize));
  55. }
  56. }
  57. }