1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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<Vector3> vec = ReadFromTxtFile(dir + reference);
- //}
- //Reads from txt files
- public Tuple<List<Vector3>, List<Quaternion>> ReadFromTxtFile(string path)
- {
- if(!File.Exists(path))
- {
- return null;
- }
-
- List<Quaternion> rotList = new List<Quaternion>();
- string[] splitPosRot = new string[] { "),(" };
- List<Vector3> posList = new List<Vector3>();
- 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);
- }
- }
|