ソースを参照

Added Cronometer utility class

James Peret 2 年 前
コミット
f64fa9ee41
2 ファイル変更60 行追加0 行削除
  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: