using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using JetBrains.Annotations; using UnityEngine; namespace Plotting { public class PlotFileWriter { private readonly StreamWriter writer; private Task previousWriteTask; public PlotFileWriter(string path) { var fileInfo = new FileInfo(path); if (!fileInfo.Directory?.Exists ?? false) { fileInfo.Directory?.Create(); } writer = new StreamWriter(path) {AutoFlush = true}; } public async Task WriteDataLine(T xValue, IEnumerable values) { await writer.WriteLineAsync($"{xValue}\t{string.Join("\t", values)}"); } public void Dispose() { writer?.Close(); } } }