DebugPlot.cs 1.4 KB

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