1234567891011121314151617181920212223242526272829303132333435363738 |
- 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>(T xValue, IEnumerable<T> values)
- {
- await writer.WriteLineAsync($"{xValue}\t{string.Join("\t", values)}");
- }
- public void Dispose()
- {
- writer?.Close();
- }
-
- }
- }
|