using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using UnityEngine; public class ProTimer :IDisposable { private string name; private int times; private Stopwatch watch; private float _runTime; public ProTimer(string name) : this(name, 0) { } public ProTimer(string name, int times) { this.name = name; this.times = times; if (this.times <= 0) { this.times = 1; } watch = Stopwatch.StartNew(); } public float RunTime { get => _runTime; } public void Dispose() { watch.Stop(); float ms = watch.ElapsedMilliseconds; _runTime = ms; if (times > 1) { UnityEngine.Debug.Log($"ProTimer:{name} finished {times} total{ms} ms, per time {ms / times} ms"); } else { UnityEngine.Debug.Log($"ProTimer:{name} finished total{ms} ms"); } } }