PolarAccData.cs 957 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using Valve.VR.InteractionSystem;
  7. public struct AccData
  8. {
  9. public long Timestamp { get; }
  10. public List<Vector3> Values { get; }
  11. AccData(long timestamp, List<Vector3> values)
  12. {
  13. this.Timestamp = timestamp;
  14. this.Values = values;
  15. }
  16. public static AccData FromString(string s)
  17. {
  18. var data = s.Split(';');
  19. if (data.Length == 2)
  20. {
  21. var t = long.Parse(data[0]);
  22. var tupleStrings = data[1].Split(',').Select(item => item.Replace("(", "").Replace(")", ""));
  23. var floats = tupleStrings.Select(s1 => s1.Split('/').Select(value => float.Parse(value)).ToList()).ToList();
  24. return new AccData(t, floats.Select(a => new Vector3(a[0], a[1], a[2])).ToList());
  25. }
  26. throw new FormatException("AccData String has wrong format");
  27. }
  28. }