CSVExport.cs 629 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using UnityEngine;
  2. using System.IO;
  3. public class CSVExport : MonoBehaviour {
  4. // Use this for initialization
  5. void Start () {
  6. }
  7. // Update is called once per frame
  8. void Update () {
  9. }
  10. public void ExportCSV(Vector3[] data, string fileName)
  11. {
  12. fileName = fileName + ".csv";
  13. if (File.Exists(fileName))
  14. {
  15. Debug.Log(fileName + " already exists.");
  16. return;
  17. }
  18. Debug.Log("started converting");
  19. var sr = File.CreateText(fileName);
  20. for (int i = 0; i < data.Length; i++)
  21. {
  22. sr.WriteLine(data[i].x + "," + data[i].y + "," + data[i].z);
  23. }
  24. Debug.Log("done");
  25. sr.Close();
  26. }
  27. }