CSVWriter.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public static class CSVWriter
  6. {
  7. private static string path = Application.dataPath + "/demo_and_body_positions.csv";
  8. public static void WriteCSV(List<List<Vector3>> posJointsDemos, List<List<Vector3>> posJointsBodys, List<float> csvTimes)
  9. {
  10. string[] jointsName = { "SpineBase", "SpineMid", "Neck", "ShoulderLeft", "ElbowLeft", "WristLeft", "ShoulderRight",
  11. "ElbowRight", "WristRight", "HipLeft", "KneeLeft", "AnkleLeft", "FootLeft", "HipRight", "KneeRight", "AnkleRight",
  12. "FootRight", "SpineShoulder" };
  13. string demos = "";
  14. string bodys = "";
  15. foreach(string name in jointsName)
  16. {
  17. demos += "Demo_" + name + ",";
  18. bodys += "Body_" + name + ",";
  19. }
  20. StreamWriter sw = new StreamWriter(path);
  21. sw.WriteLine(demos + bodys + ",time");
  22. for (int i = 0; i < posJointsDemos.Count; i++)
  23. {
  24. List<Vector3> demo = posJointsDemos[i];
  25. List<Vector3> body = posJointsDemos[i];
  26. string d = "";
  27. string b = "";
  28. for(int j = 0; i < demo.Count; j++)
  29. {
  30. d += Vector3ToString(demo[j]) + ",";
  31. b += Vector3ToString(body[j]) + ",";
  32. }
  33. sw.WriteLine(b + d + csvTimes[i]);
  34. }
  35. sw.Close();
  36. }
  37. private static string Vector3ToString(Vector3 vector)
  38. {
  39. return vector.x.ToString() + ";" + vector.y.ToString() + ";" + vector.z.ToString();
  40. }
  41. }