RenderGraphLogger.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Text;
  3. namespace UnityEngine.Experimental.Rendering.RenderGraphModule
  4. {
  5. struct RenderGraphLogIndent : IDisposable
  6. {
  7. int m_Indentation;
  8. RenderGraphLogger m_Logger;
  9. bool m_Disposed;
  10. public RenderGraphLogIndent(RenderGraphLogger logger, int indentation = 1)
  11. {
  12. m_Disposed = false;
  13. m_Indentation = indentation;
  14. m_Logger = logger;
  15. m_Logger.IncrementIndentation(m_Indentation);
  16. }
  17. public void Dispose()
  18. {
  19. Dispose(true);
  20. }
  21. void Dispose(bool disposing)
  22. {
  23. if (m_Disposed)
  24. return;
  25. if (disposing)
  26. {
  27. m_Logger.DecrementIndentation(m_Indentation);
  28. }
  29. m_Disposed = true;
  30. }
  31. }
  32. class RenderGraphLogger
  33. {
  34. StringBuilder m_Builder = new StringBuilder();
  35. int m_CurrentIndentation;
  36. public void Initialize()
  37. {
  38. m_Builder.Clear();
  39. m_CurrentIndentation = 0;
  40. }
  41. public void IncrementIndentation(int value)
  42. {
  43. m_CurrentIndentation += Math.Abs(value);
  44. }
  45. public void DecrementIndentation(int value)
  46. {
  47. m_CurrentIndentation = Math.Max(0, m_CurrentIndentation - Math.Abs(value));
  48. }
  49. public void LogLine(string format, params object[] args)
  50. {
  51. for (int i = 0; i < m_CurrentIndentation; ++i)
  52. m_Builder.Append('\t');
  53. m_Builder.AppendFormat(format, args);
  54. m_Builder.AppendLine();
  55. }
  56. public string GetLog()
  57. {
  58. return m_Builder.ToString();
  59. }
  60. }
  61. }