123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using Logging.Base;
- using UnityEngine;
- namespace Logging.Data
- {
- public readonly struct BikeGameObjectDataLog : ISerializable
- {
- private readonly long timestamp;
- private readonly float positionX;
- private readonly float positionY;
- private readonly float positionZ;
- private readonly float rotationX;
- private readonly float rotationY;
- private readonly float rotationZ;
- private readonly float velocityX;
- private readonly float velocityY;
- private readonly float velocityZ;
- private readonly int collisionCounter;
- private readonly int coinCounter;
- private readonly int hasFinished;
- private readonly int hasFinishedSlalom1;
- private readonly int hasFinishedSlalom2;
- private readonly string condition;
- public BikeGameObjectDataLog(long timestamp, float positionX, float positionY, float positionZ, float rotationX,
- float rotationY, float rotationZ, float velocityX, float velocityY, float velocityZ, int collisionCounter, int coinCounter,
- int hasFinished, int hasFinishedSlalom1, int hasFinishedSlalom2, string condition)
- {
- this.timestamp = timestamp;
- this.positionX = positionX;
- this.positionY = positionY;
- this.positionZ = positionZ;
- this.rotationX = rotationX;
- this.rotationY = rotationY;
- this.rotationZ = rotationZ;
- this.velocityX = velocityX;
- this.velocityY = velocityY;
- this.velocityZ = velocityZ;
- this.collisionCounter = collisionCounter;
- this.coinCounter = coinCounter;
- this.hasFinished = hasFinished;
- this.hasFinishedSlalom1 = hasFinishedSlalom1;
- this.hasFinishedSlalom2 = hasFinishedSlalom2;
- this.condition = condition;
- }
- public KeyValuePair<long, string[]> Serialize()
- {
- return new KeyValuePair<long, string[]>(
- timestamp, new[]
- {
- positionX.ToString("F6", CultureInfo.InvariantCulture),
- positionY.ToString("F6", CultureInfo.InvariantCulture),
- positionZ.ToString("F6", CultureInfo.InvariantCulture),
- rotationX.ToString("F6", CultureInfo.InvariantCulture),
- rotationY.ToString("F6", CultureInfo.InvariantCulture),
- rotationZ.ToString("F6", CultureInfo.InvariantCulture),
- velocityX.ToString("F6", CultureInfo.InvariantCulture),
- velocityY.ToString("F6", CultureInfo.InvariantCulture),
- velocityZ.ToString("F6", CultureInfo.InvariantCulture),
- collisionCounter.ToString("F6", CultureInfo.InvariantCulture),
- coinCounter.ToString("F6", CultureInfo.InvariantCulture),
- hasFinished.ToString("F6", CultureInfo.InvariantCulture),
- hasFinishedSlalom1.ToString("F6", CultureInfo.InvariantCulture),
- hasFinishedSlalom2.ToString("F6", CultureInfo.InvariantCulture),
- condition,
- });
- }
- }
- public class BikeGameObjectDataLogger : SensorDataLogger<BikeGameObjectDataLog>
- {
- public Rigidbody bike;
- private Transform bikeTransform;
- public override string Key => "bike_game_object_data";
- public GameObject bikePlayer;
- public override void Start()
- {
- base.Start();
- bikeTransform = bike.transform;
- // TODO: This is a bit crude
- bikePlayer = GameObject.Find("bike");
- }
- private void Update()
- {
- var pos = bikeTransform.position;
- var rot = bikeTransform.rotation.eulerAngles;
- var velocity = bike.velocity;
- var playerStats = bikePlayer.GetComponent<PlayerStats>();
- Log(new BikeGameObjectDataLog(Helpers.RoundToLong(Time.time * 1000),
- pos.x, pos.y, pos.z,
- rot.x, rot.y, rot.z,
- velocity.x, velocity.y, velocity.z,
- playerStats.collisionCounter,
- playerStats.coinCounter,
- playerStats.hasFinished,
- playerStats.hasFinishedSlalom1,
- playerStats.hasFinishedSlalom2,
- playerStats.condition
- ));
- }
- public override IEnumerable<BikeGameObjectDataLog> ReadLog(IEnumerable<IEnumerable<string>> lines)
- {
- throw new NotImplementedException(); //TODO
- }
- }
- }
|