123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using UnityEngine;
- using System.Globalization;
- using System.Collections.Generic;
- using System.IO;
- using System;
- public class ReadFromCSV : MonoBehaviour
- {
- //private void Start()
- //{
- // string dir = Directory.GetCurrentDirectory();
- // string reference = @"\Assets\CSV_files\Walk1.txt";
- // List<Vector3> vec = ReadFromTxtFile(dir + reference);
- //}
- //Reads from csv files
- public Tuple<List<Vector3>, List<Quaternion>> ReadFromCSVFile(string path)
- {
- if(!File.Exists(path))
- {
- return null;
- }
- List<Vector3> posList = new List<Vector3>();
- List<Quaternion> rotList = new List<Quaternion>();
- using (StreamReader reader = new StreamReader(path, true))
- {
- // Skip header
- reader.ReadLine();
- while (!reader.EndOfStream)
- {
- var line = reader.ReadLine();
- var values = line.Split(';');
- // Adding into position list
- posList.Add(new Vector3(
- float.Parse(values[0]),
- float.Parse(values[1]),
- float.Parse(values[2])));
- // Adding into rotation list
- rotList.Add(new Quaternion(
- float.Parse(values[3]),
- float.Parse(values[4]),
- float.Parse(values[5]),
- float.Parse(values[6])));
- }
- }
-
- return Tuple.Create(posList, rotList);
- }
- }
|