Browse Source

FMS countdown

Marcel Zickler 3 years ago
parent
commit
018b0e4d71

+ 1 - 0
Assembly-CSharp.csproj

@@ -373,6 +373,7 @@
      <Compile Include="Assets\AdvancedAnt\Scripts\SpeedDisplay.cs" />
      <Compile Include="Assets\AdvancedAnt\Plugins\Ant\Fit\Mesg.cs" />
      <Compile Include="Assets\Scripts\Sensors\ANT\AntDevices.cs" />
+     <Compile Include="Assets\Scripts\Logging\FMSCountdown.cs" />
      <None Include="Assets\TextMesh Pro\Shaders\TMPro.cginc" />
      <None Include="Assets\TextMesh Pro\Shaders\TMP_SDF-Mobile Overlay.shader" />
      <None Include="Assets\AdvancedAnt\Plugins\Ant\License.txt" />

+ 46 - 0
Assets/Scripts/Logging/FMSCountdown.cs

@@ -0,0 +1,46 @@
+using Routes;
+using UnityEngine;
+
+namespace Logging
+{
+    public class FMSCountdown : MonoBehaviour
+    {
+        public RouteManager routeManager;
+        public int fmsInterval = 30;
+
+        private float startTime = -1f;
+        private float timestampLastFMS;
+
+        private GUIStyle bigRedTextStyle;
+
+        private void Start()
+        {
+            bigRedTextStyle = new GUIStyle {fontSize = 72, normal = new GUIStyleState {textColor = Color.red}};
+            var activeRoute = routeManager.routes[routeManager.selectedRoute];
+            activeRoute.OnStartEntered += () =>
+            {
+                startTime = Time.time;
+                timestampLastFMS = startTime;
+            };
+            activeRoute.OnFinishPassed += () => gameObject.SetActive(false);
+        }
+
+        private void OnGUI()
+        {
+            if (startTime < 0) return;
+            var time = Time.time - startTime;
+            var timeFromLastFms = Time.time - timestampLastFMS;
+            GUI.TextField(new Rect(20, 85, 200, 20), $"Seconds Passed: {time:N2}");
+
+            var distToInterval = fmsInterval - timeFromLastFms;
+            if (distToInterval <= 1 || distToInterval >= fmsInterval - 2 && time > fmsInterval) //show a second before and 2 after
+            {
+                GUI.TextField(new Rect(225, 65, 120, 100), "FMS!", bigRedTextStyle);
+                if (distToInterval <= 0) // set timestamp for next interval
+                {
+                    timestampLastFMS = Time.time;
+                }
+            }
+        }
+    }
+}

+ 3 - 0
Assets/Scripts/Logging/FMSCountdown.cs.meta

@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 6a5ebbc316984e519ae9c703bb29f643
+timeCreated: 1621251811

+ 4 - 5
Assets/Scripts/Routes/RouteManager.cs

@@ -19,8 +19,8 @@ namespace Routes
         {
             for (var i = 0; i < routes.Length; i++) routes[i].gameObject.SetActive(i == selectedRoute);
 
-            routes[selectedRoute].OnStartEntered += OnOnStartEntered;
-            routes[selectedRoute].OnFinishPassed += OnOnFinishPassed;
+            routes[selectedRoute].OnStartEntered += OnStartEntered;
+            routes[selectedRoute].OnFinishPassed += OnFinishPassed;
 
             PlaceBike();
         }
@@ -30,7 +30,6 @@ namespace Routes
             var firstTurnPos = routes[selectedRoute].items.First().turn.transform.position;
 
             var startTransform = routes[selectedRoute].start.gameObject.transform;
-            var startRotationEuler = startTransform.rotation.eulerAngles;
 
             var difStartFirstTurn = firstTurnPos - startTransform.position;
             var bikeDirection = Vector3.zero;
@@ -49,14 +48,14 @@ namespace Routes
             bicycleGameObject.transform.LookAt(startTransform);
         }
 
-        private void OnOnFinishPassed()
+        private void OnFinishPassed()
         {
             //bicycle.enabled = false;
             Instantiate(showOnFinish, bicycle.transform);
             Destroy(logging.gameObject);
         }
 
-        private void OnOnStartEntered()
+        private void OnStartEntered()
         {
             logging.gameObject.SetActive(true);
         }