1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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<IBicycleController>();
- sensorData = BikeSensorData.Instance;
- player = GameObject.FindGameObjectWithTag("HMDTracker");
- // Dummy assignment
- steeringSelection = SteeringMode.HMD;
- }
- private void Update()
- {
- 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
- bicycleController.CurrentSteerAngle = player.transform.rotation.y;
- Debug.Log("Updating Steering Angle to " + bicycleController.CurrentSteerAngle);
- break;
- }
- }
- private void SetLeaningAngle()
- {
- //bicycleController.CurrentLeaningAngle =
- }
- private void SetSpeed(SpeedSensorData speedData)
- {
- bicycleController.CurrentSpeed = speedData.Speed;
- }
- }
- }
|