DebugPlot.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using Logging;
  6. using Logging.Base;
  7. using UnityEngine;
  8. namespace Plotting
  9. {
  10. public class DebugPlot
  11. {
  12. #region signleton
  13. private static Lazy<DebugPlot>
  14. instance =
  15. new Lazy<DebugPlot>
  16. (() => new DebugPlot());
  17. public static DebugPlot Instance => instance.Value;
  18. public static void DestroyInstance()
  19. {
  20. if (instance.IsValueCreated)
  21. {
  22. instance.Value.Dispose();
  23. instance =
  24. new Lazy<DebugPlot>
  25. (() => new DebugPlot());
  26. }
  27. }
  28. #endregion
  29. private List<AsyncLogFileWriter> plotWriters = new List<AsyncLogFileWriter>();
  30. private Process plottingProc;
  31. private DebugPlot()
  32. { }
  33. public AsyncLogFileWriter StartPlotting(string path)
  34. {
  35. var writer = new AsyncLogFileWriter(path);
  36. plotWriters.Add(writer);
  37. return writer;
  38. }
  39. public void ShowPlots()
  40. {
  41. plottingProc = Process.Start("CMD.exe",$"/C cd Assets/Plotting & python plot.py");
  42. }
  43. private void Dispose()
  44. {
  45. plottingProc?.Kill();
  46. foreach (var p in plotWriters)
  47. {
  48. p.Dispose();
  49. }
  50. }
  51. }
  52. }