Browse Source

Added Cronometer utility class

James Peret 1 year ago
parent
commit
f64fa9ee41
2 changed files with 60 additions and 0 deletions
  1. 49 0
      Runtime/Cronometer.cs
  2. 11 0
      Runtime/Cronometer.cs.meta

+ 49 - 0
Runtime/Cronometer.cs

@@ -0,0 +1,49 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace KairoEngine.Core
+{
+    public class Cronometer
+    {
+        
+        private float startTime;
+        private float stopTime;
+        private float totalTime;
+        private bool running = false;
+
+        public Cronometer()
+        {
+            startTime = Time.realtimeSinceStartup;
+            running = true;
+        }
+
+        public void Start()
+        {
+            if(!running)
+            {
+                running = true;
+                startTime = Time.realtimeSinceStartup;
+            }
+        }
+
+        public Cronometer Stop()
+        {
+            if(running)
+            {
+                stopTime = Time.realtimeSinceStartup;
+                totalTime += stopTime - startTime;
+                running = false;
+                startTime = 0f;
+                stopTime = 0f;
+            }
+            return this;
+        }
+
+        public void Continue() => Start();
+
+        public float value => totalTime;
+
+        public string Print() => Utilities.TimeToString(value);
+    }
+}

+ 11 - 0
Runtime/Cronometer.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ba7320bc5a976f64494367049aaf103f
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: