using System.Collections.Generic; using System.Diagnostics; using EventCubeMelt; using UnityEngine; using Debug = UnityEngine.Debug; namespace EventCubeMelt.Utils { public class ProfileScope { private Stopwatch sw; private string scopeName; private Dictionary s_accum = new Dictionary(); public void L_ProfileScope(string sectionName) { scopeName = sectionName; sw = Stopwatch.StartNew(); } public void L_ProfileScopeEnd() { sw.Stop(); long el = sw.ElapsedMilliseconds; s_accum.TryGetValue(scopeName, out long old); s_accum[scopeName] = old + el; ELog($"{scopeName} 本次 {el} ms 累计 {s_accum[scopeName]} ms"); } #region Log private static void ELog(string message) { #if UNITY_EDITOR if (!EventCubeMeltLogPolicy.EnableELog) return; Debug.Log($"ProfileScope => {message} "); #endif } #endregion } }