using UnityEngine; using System.Globalization; using System.Collections.Generic; using System.IO; using System; public class ReadFromFileOld : MonoBehaviour { //private void Start() //{ // string dir = Directory.GetCurrentDirectory(); // string reference = @"\Assets\Data_position\Walk1.txt"; // List vec = ReadFromTxtFile(dir + reference); //} //Reads from txt files public Tuple, List> ReadFromTxtFile(string path) { if(!File.Exists(path)) { return null; } List rotList = new List(); string[] splitPosRot = new string[] { "),(" }; List posList = new List(); char[] seperator = new char[] { ',' }; foreach (string line in File.ReadLines(path)) { if(line != null) { // removing parentheses string lineCleaned = line.Substring(1, line.Length - 2); // splitting into 0 -> Position and 1 -> Rotation string[] posRow = lineCleaned.Split(splitPosRot, StringSplitOptions.RemoveEmptyEntries); // Adding into position list string[] pos = posRow[0].Split(seperator, StringSplitOptions.RemoveEmptyEntries); posList.Add(new Vector3( float.Parse(pos[0], CultureInfo.InvariantCulture), float.Parse(pos[1], CultureInfo.InvariantCulture), float.Parse(pos[2], CultureInfo.InvariantCulture))); // Adding into rotation list string[] rot = posRow[1].Split(seperator, StringSplitOptions.RemoveEmptyEntries); rotList.Add(new Quaternion( float.Parse(rot[0], CultureInfo.InvariantCulture), float.Parse(rot[1], CultureInfo.InvariantCulture), float.Parse(rot[2], CultureInfo.InvariantCulture), float.Parse(rot[3], CultureInfo.InvariantCulture))); } } return Tuple.Create(posList, rotList); } }