using System; using Controller.Bicycle; using Controller.Lean; using Sensors; using Sensors.ANT; using Tracking; using UnityEngine; namespace Controller { [Serializable] public struct FrontWheelTrackerConfig { public FrontWheelTracker frontWheelTracker; public float multiplicator; public float AdjustedRotation => frontWheelTracker.SteerRotation * multiplicator; } [RequireComponent(typeof(IBicycleController))] public class SensorBikeController : MonoBehaviour { public enum SteeringMode { frontWheel, Leaning, HMD }; public PolarRotationMapping polarRotationMapping; public FrontWheelTrackerConfig frontWheelTrackerConfig; public bool steer = true; public bool accelerate = true; public bool lean = true; public SteeringMode steeringSelection; private IBicycleController bicycleController; private bool isFrontWheelTrackerNotNull; private BikeSensorData sensorData; private GameObject player; private void Start() { isFrontWheelTrackerNotNull = frontWheelTrackerConfig.frontWheelTracker != null; bicycleController = GetComponent(); sensorData = BikeSensorData.Instance; player = GameObject.FindGameObjectWithTag("HMDTracker"); // Dummy assignment steeringSelection = SteeringMode.frontWheel; } private void Update() { Debug.Log("Bike Sensor Controller called"); var speedData = sensorData.SpeedData; if (speedData != null && accelerate) SetSpeed(speedData.Value); if (steer) SetSteer(); if (lean) SetLeaningAngle(); } private void SetSteer() { Debug.Log("Updating Steering"); switch (steeringSelection) { case SteeringMode.frontWheel: if (isFrontWheelTrackerNotNull) { bicycleController.CurrentSteerAngle = frontWheelTrackerConfig.AdjustedRotation; } break; case SteeringMode.Leaning: // TBD bicycleController.CurrentSteerAngle = 0; break; case SteeringMode.HMD: // TODO: Convert steering relative to bike Debug.Log("HMD Rotation " + player.transform.eulerAngles); bicycleController.CurrentSteerAngle = player.transform.eulerAngles.y; break; } //Debug.Log("Updating Steering Angle to " + bicycleController.CurrentSteerAngle); } private void SetLeaningAngle() { //bicycleController.CurrentLeaningAngle = } private void SetSpeed(SpeedSensorData speedData) { bicycleController.CurrentSpeed = speedData.Speed; } } }