1
0

DebugPlot.cs 1.4 KB

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