ReadFromCSVOld.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using UnityEngine;
  2. using System.Globalization;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System;
  6. public class ReadFromCSVOld : MonoBehaviour
  7. {
  8. //private void Start()
  9. //{
  10. // string dir = Directory.GetCurrentDirectory();
  11. // string reference = @"\Assets\Data_position\Walk1.txt";
  12. // List<Vector3> vec = ReadFromTxtFile(dir + reference);
  13. //}
  14. //Reads from csv files
  15. public Tuple<List<Vector3>, List<Quaternion>> ReadFromCSVFile(string path)
  16. {
  17. if(!File.Exists(path))
  18. {
  19. return null;
  20. }
  21. List<Vector3> posList = new List<Vector3>();
  22. List<Quaternion> rotList = new List<Quaternion>();
  23. using (StreamReader reader = new StreamReader(path, true))
  24. {
  25. // Skip header
  26. reader.ReadLine();
  27. while (!reader.EndOfStream)
  28. {
  29. var line = reader.ReadLine();
  30. var values = line.Split(';');
  31. // Adding into position list
  32. posList.Add(new Vector3(
  33. float.Parse(values[0]),
  34. float.Parse(values[1]),
  35. float.Parse(values[2])));
  36. // Adding into rotation list
  37. rotList.Add(new Quaternion(
  38. float.Parse(values[3]),
  39. float.Parse(values[4]),
  40. float.Parse(values[5]),
  41. float.Parse(values[6])));
  42. }
  43. }
  44. return Tuple.Create(posList, rotList);
  45. }
  46. }