Selaa lähdekoodia

More Interface stuff

Marcel Zickler 3 vuotta sitten
vanhempi
commit
66c21c7444

+ 1 - 0
Assembly-CSharp.csproj

@@ -259,6 +259,7 @@
      <Compile Include="Assets\Scripts\Calibration\MovePlayerPosition.cs" />
      <Compile Include="Assets\Scripts\Calibration\PersistatePlayerPosition.cs" />
      <Compile Include="Assets\Scripts\Controller\Bicycle\IBicycleController.cs" />
+     <Compile Include="Assets\Scripts\Controller\Bicycle\RbBicycleController.cs" />
      <Compile Include="Assets\Scripts\Controller\Bicycle\WcBicycleController.cs" />
      <Compile Include="Assets\Scripts\Controller\Bicycle\WheelConfig.cs" />
      <Compile Include="Assets\Scripts\Controller\GamepadBikeController.cs" />

+ 12 - 0
Assets/Scripts/Controller/Bicycle/RbBicycleController.cs

@@ -0,0 +1,12 @@
+using UnityEngine;
+
+namespace Controller.Bicycle
+{
+    public class RbBicycleController : MonoBehaviour, IBicycleController
+    {
+        public BicycleControllerMode ControllerMode { get; set; }
+        public float CurrentSpeed { get; set; }
+        public float CurrentLeaningAngle { get; set; }
+        public float CurrentSteerAngle { get; set; }
+    }
+}

+ 3 - 0
Assets/Scripts/Controller/Bicycle/RbBicycleController.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: e9349e7eecd845c3a526e46930a4fc32
+timeCreated: 1607503961

+ 11 - 5
Assets/Scripts/Controller/Bicycle/WcBicycleController.cs

@@ -20,9 +20,10 @@ namespace Controller.Bicycle
         [Header("Values")] public float offsetCollidersFromWheel = 0.25f;
         public float maxLeaningAngle = 35f;
         public float maxSteeringAngle = 80f;
-        [Range(0,15)]
-        [Tooltip("Speed in m/s")]
+
+        [Range(0, 15)] [Tooltip("Speed in m/s")]
         public float maxSpeed = 11.111f; //40 km/h
+
         public float maxBreakTorque = 2000f;
         public float maxMotorTorque = 1000f;
 
@@ -37,7 +38,12 @@ namespace Controller.Bicycle
         public float CurrentSteerAngle
         {
             get => currentSteerAngle;
-            set => currentSteerAngle = Mathf.Clamp(value, -maxSteeringAngle, maxSteeringAngle);
+            set
+            {
+                //don't lean while standing / walking to bike
+                if (rigidBody.velocity.magnitude < .5f) return;
+                currentSteerAngle = Mathf.Clamp(value, -maxSteeringAngle, maxSteeringAngle);
+            }
         }
 
         public float CurrentLeaningAngle
@@ -92,11 +98,11 @@ namespace Controller.Bicycle
             var rbSpeed = rigidBody.velocity.magnitude;
             var speedDif = CurrentSpeed - rbSpeed;
             var ratio = speedDif / maxSpeed;
-           
+
 
             var brakeTorque = 0f;
             var motorTorque = 0f;
-            
+
             if (speedDif >= .1f) // 0.36 km/h
             {
                 var torque = maxMotorTorque * ratio;

+ 6 - 6
Assets/Scripts/Controller/GamepadBikeController.cs

@@ -6,7 +6,7 @@ using UnityEngine.InputSystem;
 namespace Controller
 {
     [RequireComponent(typeof(PlayerInput))]
-    [RequireComponent(typeof(WcBicycleController))]
+    [RequireComponent(typeof(IBicycleController))]
     public class GamepadBikeController : MonoBehaviour
     {
         public bool useSpeed;
@@ -20,18 +20,18 @@ namespace Controller
         private float acceleration;
         private float lean;
         private float steer;
-        private WcBicycleController wcBicycleController;
+        private IBicycleController bicycleController;
 
         private void Start()
         {
-            wcBicycleController = GetComponent<WcBicycleController>();
+            bicycleController = GetComponent<IBicycleController>();
         }
 
         private void Update()
         {
-            if (useSteer) wcBicycleController.CurrentSteerAngle = steer;
-            if (useLean) wcBicycleController.CurrentLeaningAngle = lean;
-            if (useSpeed) wcBicycleController.CurrentSpeed += acceleration;
+            if (useSteer) bicycleController.CurrentSteerAngle = steer;
+            if (useLean) bicycleController.CurrentLeaningAngle = lean;
+            if (useSpeed) bicycleController.CurrentSpeed += acceleration;
         }
 
         [UsedImplicitly]

+ 15 - 14
Assets/Scripts/Controller/KeyboardBikeController.cs

@@ -3,9 +3,10 @@ using UnityEngine;
 
 namespace Controller
 {
+    [RequireComponent(typeof(IBicycleController))]
     public class KeyboardBikeController : MonoBehaviour
     {
-        private WcBicycleController wcBicycleController;
+        private IBicycleController bicycleController;
 
         public bool steer = true;
         public bool lean = true;
@@ -19,7 +20,7 @@ namespace Controller
 
         private void Start()
         {
-            wcBicycleController = GetComponent<WcBicycleController>();
+            bicycleController = GetComponent<IBicycleController>();
         }
 
         private void Update()
@@ -28,18 +29,18 @@ namespace Controller
             {
                 if (Input.GetKey(KeyCode.T))
                 {
-                    wcBicycleController.CurrentSpeed += speedIncreasePerSecond * Time.deltaTime;
+                    bicycleController.CurrentSpeed += speedIncreasePerSecond * Time.deltaTime;
                 }
-                else if (wcBicycleController.CurrentSpeed > 0)
+                else if (bicycleController.CurrentSpeed > 0)
                 {
-                    wcBicycleController.CurrentSpeed = Mathf.Max(0,
-                        wcBicycleController.CurrentSpeed - speedDecreasePerSecond * Time.deltaTime);
+                    bicycleController.CurrentSpeed = Mathf.Max(0,
+                        bicycleController.CurrentSpeed - speedDecreasePerSecond * Time.deltaTime);
                 }
 
                 if (Input.GetKey(KeyCode.G))
                 {
-                    wcBicycleController.CurrentSpeed = Mathf.Max(0,
-                        wcBicycleController.CurrentSpeed - brakeIncreasePerSecond * Time.deltaTime);
+                    bicycleController.CurrentSpeed = Mathf.Max(0,
+                        bicycleController.CurrentSpeed - brakeIncreasePerSecond * Time.deltaTime);
                 }
             }
 
@@ -47,17 +48,17 @@ namespace Controller
             {
                 if (Input.GetKey(KeyCode.F))
                 {
-                    wcBicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
+                    bicycleController.CurrentSteerAngle -= steeringAngleIncreasePerSecond * Time.deltaTime;
                 }
 
                 if (Input.GetKey(KeyCode.H))
                 {
-                    wcBicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
+                    bicycleController.CurrentSteerAngle += steeringAngleIncreasePerSecond * Time.deltaTime;
                 }
 
                 if (Input.GetKeyUp(KeyCode.F) || Input.GetKeyUp(KeyCode.H))
                 {
-                    wcBicycleController.CurrentSteerAngle = 0f;
+                    bicycleController.CurrentSteerAngle = 0f;
                 }
             }
 
@@ -65,17 +66,17 @@ namespace Controller
             {
                 if (Input.GetKey(KeyCode.R))
                 {
-                    wcBicycleController.CurrentLeaningAngle -= leaningAngleIncreasePerSecond * Time.deltaTime;
+                    bicycleController.CurrentLeaningAngle -= leaningAngleIncreasePerSecond * Time.deltaTime;
                 }
 
                 if (Input.GetKey(KeyCode.Z))
                 {
-                    wcBicycleController.CurrentLeaningAngle += leaningAngleIncreasePerSecond * Time.deltaTime;
+                    bicycleController.CurrentLeaningAngle += leaningAngleIncreasePerSecond * Time.deltaTime;
                 }
 
                 if (Input.GetKeyUp(KeyCode.R) || Input.GetKeyUp(KeyCode.Z))
                 {
-                    wcBicycleController.CurrentLeaningAngle = 0f;
+                    bicycleController.CurrentLeaningAngle = 0f;
                 }
             }
         }

+ 7 - 11
Assets/Scripts/Controller/SensorBikeController.cs

@@ -25,6 +25,7 @@ namespace Controller
         public Vector3 AdjustedRotation => frontWheelTracker.Rotation * multiplicator;
     }
 
+    [RequireComponent(typeof(IBicycleController))]
     public class SensorBikeController : MonoBehaviour
     {
         public PolarRotationMapping polarRotationMapping;
@@ -37,7 +38,7 @@ namespace Controller
         public bool accelerate = true;
         public bool lean = true;
 
-        private WcBicycleController wcBicycleController;
+        private IBicycleController bicycleController;
         private BikeSensorData sensorData;
         private float leanFactor;
         private bool isFrontWheelTrackerNotNull;
@@ -45,7 +46,7 @@ namespace Controller
         private async void Start()
         {
             isFrontWheelTrackerNotNull = frontWheelTrackerConfig.frontWheelTracker != null;
-            wcBicycleController = GetComponent<WcBicycleController>();
+            bicycleController = GetComponent<IBicycleController>();
             sensorData = BikeSensorData.Instance;
             await sensorData.StartListening(polarSensorConfig: polarSensorConfig, speedSensorConfig: speedSensorConfig);
             leanFactor = 90f / (polarRotationMapping.maxRight - polarRotationMapping.center);
@@ -74,7 +75,8 @@ namespace Controller
 
         private void SetSteer()
         {
-            wcBicycleController.CurrentSteerAngle = frontWheelTrackerConfig.AdjustedRotation.y; //TODO: something a bit smarter
+            bicycleController.CurrentSteerAngle =
+                frontWheelTrackerConfig.AdjustedRotation.y; //TODO: something a bit smarter
         }
 
         private void OnDestroy()
@@ -84,18 +86,12 @@ namespace Controller
 
         private void SetLeaningAngle(PolarSensorData polarData)
         {
-            //don't lean while standing / walking to bike
-            if (wcBicycleController.rigidBody.velocity.magnitude > .5f)
-            {
-                wcBicycleController.CurrentLeaningAngle = (polarData.Acc.y - polarRotationMapping.center) * leanFactor;
-            }
+            bicycleController.CurrentLeaningAngle = (polarData.Acc.y - polarRotationMapping.center) * leanFactor;
         }
 
         private void SetSpeed(SpeedSensorData speedData)
         {
-            wcBicycleController.CurrentSpeed = speedData.Speed;
-            
-            
+            bicycleController.CurrentSpeed = speedData.Speed;
         }
     }
 }

+ 4 - 3
Assets/Scripts/Controller/ViveBikeController.cs

@@ -4,24 +4,25 @@ using Valve.VR;
 
 namespace Controller
 {
+    [RequireComponent(typeof(IBicycleController))]
     public class ViveBikeController : MonoBehaviour
     {
         public SteamVR_Action_Pose steerPose;
         public float multiplier = 40f;
 
-        private WcBicycleController wcBicycleController;
+        private IBicycleController bicycleController;
     
         // Start is called before the first frame update
         void Start()
         {
-            wcBicycleController = GetComponent<WcBicycleController>();
+            bicycleController = GetComponent<IBicycleController>();
         }
 
         // Update is called once per frame
         void Update()
         {
             var rot = steerPose.localRotation.y;
-            wcBicycleController.CurrentSteerAngle = rot * multiplier;
+            bicycleController.CurrentSteerAngle = rot * multiplier;
         }
     }
 }