1
0

BikeGameObjectDataLogger.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections.Generic;
  2. using System.Globalization;
  3. using Logging.Base;
  4. using UnityEngine;
  5. namespace Logging.Data
  6. {
  7. public readonly struct BikeGameObjectDataLog : ISerializable
  8. {
  9. private readonly long timestamp;
  10. private readonly float positionX;
  11. private readonly float positionY;
  12. private readonly float positionZ;
  13. private readonly float rotationX;
  14. private readonly float rotationY;
  15. private readonly float rotationZ;
  16. private readonly float velocityX;
  17. private readonly float velocityY;
  18. private readonly float velocityZ;
  19. public BikeGameObjectDataLog(long timestamp, float positionX, float positionY, float positionZ, float rotationX,
  20. float rotationY, float rotationZ, float velocityX, float velocityY, float velocityZ)
  21. {
  22. this.timestamp = timestamp;
  23. this.positionX = positionX;
  24. this.positionY = positionY;
  25. this.positionZ = positionZ;
  26. this.rotationX = rotationX;
  27. this.rotationY = rotationY;
  28. this.rotationZ = rotationZ;
  29. this.velocityX = velocityX;
  30. this.velocityY = velocityY;
  31. this.velocityZ = velocityZ;
  32. }
  33. public KeyValuePair<long, string[]> Serialize() => new KeyValuePair<long, string[]>(
  34. timestamp, new[]
  35. {
  36. positionX.ToString("F6", CultureInfo.InvariantCulture),
  37. positionY.ToString("F6", CultureInfo.InvariantCulture),
  38. positionZ.ToString("F6", CultureInfo.InvariantCulture),
  39. rotationX.ToString("F6", CultureInfo.InvariantCulture),
  40. rotationY.ToString("F6", CultureInfo.InvariantCulture),
  41. rotationZ.ToString("F6", CultureInfo.InvariantCulture),
  42. velocityX.ToString("F6", CultureInfo.InvariantCulture),
  43. velocityY.ToString("F6", CultureInfo.InvariantCulture),
  44. velocityZ.ToString("F6", CultureInfo.InvariantCulture)
  45. });
  46. }
  47. public class BikeGameObjectDataLogger : SensorDataLogger<BikeGameObjectDataLog>
  48. {
  49. public Rigidbody bike;
  50. private Transform bikeTransform;
  51. public override string Key => "bike_game_object_data";
  52. public override void Start()
  53. {
  54. base.Start();
  55. bikeTransform = bike.transform;
  56. }
  57. private void Update()
  58. {
  59. var pos = bikeTransform.position;
  60. var rot = bikeTransform.rotation.eulerAngles;
  61. var velocity = bike.velocity;
  62. Log(new BikeGameObjectDataLog(Helpers.RoundToLong(Time.time * 1000),
  63. pos.x, pos.y, pos.z,
  64. rot.x, rot.y, rot.z,
  65. velocity.x, velocity.y, velocity.z));
  66. }
  67. public override IEnumerable<BikeGameObjectDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
  68. {
  69. throw new System.NotImplementedException(); //TODO
  70. }
  71. }
  72. }