using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public static class CSVWriter { private static readonly string path = Application.dataPath + "/demo_and_body_positions.csv"; public static void WriteCSV(List> posJointsDemos, List> posJointsBodys, List csvTimes) { string[] jointsName = { "SpineBase", "SpineMid", "Neck", "ShoulderLeft", "ElbowLeft", "WristLeft", "ShoulderRight", "ElbowRight", "WristRight", "HipLeft", "KneeLeft", "AnkleLeft", "FootLeft", "HipRight", "KneeRight", "AnkleRight", "FootRight", "SpineShoulder" }; string demos = ""; string bodys = ""; foreach(string name in jointsName) { demos += "Demo_" + name + ","; bodys += "Body_" + name + ","; } StreamWriter sw = new StreamWriter(path); sw.WriteLine(demos + bodys + "time"); for (int i = 0; i < posJointsDemos.Count; i++) { List demo = posJointsDemos[i]; List body = posJointsBodys[i]; string d = ""; string b = ""; for(int j = 0; j < demo.Count; j++) { d += Vector3ToString(demo[j]) + ","; b += Vector3ToString(body[j]) + ","; } sw.WriteLine(b + d + csvTimes[i]); } sw.Close(); } private static string Vector3ToString(Vector3 vector) { return vector.x.ToString() + ";" + vector.y.ToString() + ";" + vector.z.ToString(); } }