This commit is contained in:
陈思海 2026-04-27 11:01:30 +08:00
parent 9acea7f00c
commit 4c134af495
5 changed files with 16 additions and 28 deletions

View File

@ -56,7 +56,7 @@ namespace AlicizaX.Timer.Editor
return;
}
if (timerService is not ITimerServiceDebugView debugView)
if (timerService is not ITimerServiceDebug debugView)
{
return;
}
@ -80,7 +80,7 @@ namespace AlicizaX.Timer.Editor
#endif
}
private void DrawTimerList(ITimerServiceDebugView debugView, int activeCount)
private void DrawTimerList(ITimerServiceDebug debug, int activeCount)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Active Timers", EditorStyles.boldLabel);
@ -92,7 +92,7 @@ namespace AlicizaX.Timer.Editor
}
EnsureTimerBuffer(activeCount);
int timerCount = debugView.GetAllTimers(_timerBuffer);
int timerCount = debug.GetAllTimers(_timerBuffer);
int displayCount = Mathf.Min(timerCount, MAX_DISPLAY_COUNT);
if (displayCount < timerCount)
@ -120,7 +120,7 @@ namespace AlicizaX.Timer.Editor
}
#if UNITY_EDITOR
private void DrawLeakDetection(ITimerServiceDebugView debugView, int activeCount)
private void DrawLeakDetection(ITimerServiceDebug debug, int activeCount)
{
if (activeCount <= 0)
{
@ -128,7 +128,7 @@ namespace AlicizaX.Timer.Editor
}
EnsureLeakBuffer(activeCount);
int staleCount = debugView.GetStaleOneShotTimers(_leakBuffer);
int staleCount = debug.GetStaleOneShotTimers(_leakBuffer);
if (staleCount <= 0)
{
return;

View File

@ -17,7 +17,7 @@ namespace AlicizaX.Debugger.Runtime
public Label Value;
}
private ITimerServiceDebugView m_TimerDebugView;
private ITimerServiceDebug _mTimerDebug;
private TimerDebugInfo[] m_TimerInfos;
private Label m_SectionTitleLabel;
private Label m_ActiveCountLabel;
@ -31,12 +31,12 @@ namespace AlicizaX.Debugger.Runtime
public override void Initialize(params object[] args)
{
m_TimerDebugView = AppServices.Require<ITimerService>() as ITimerServiceDebugView;
_mTimerDebug = AppServices.Require<ITimerService>() as ITimerServiceDebug;
}
protected override void BuildWindow(VisualElement root)
{
if (m_TimerDebugView == null)
if (_mTimerDebug == null)
{
return;
}
@ -74,12 +74,12 @@ namespace AlicizaX.Debugger.Runtime
private void RefreshContent()
{
if (m_TimerDebugView == null)
if (_mTimerDebug == null)
{
return;
}
m_TimerDebugView.GetStatistics(out int activeCount, out int poolCapacity, out int peakActiveCount, out int freeCount);
_mTimerDebug.GetStatistics(out int activeCount, out int poolCapacity, out int peakActiveCount, out int freeCount);
float poolUsage = poolCapacity > 0 ? (float)activeCount / poolCapacity : 0f;
m_ActiveCountLabel.text = activeCount.ToString();
@ -100,7 +100,7 @@ namespace AlicizaX.Debugger.Runtime
}
EnsureTimerInfoBuffer(activeCount);
int timerCount = m_TimerDebugView.GetAllTimers(m_TimerInfos);
int timerCount = _mTimerDebug.GetAllTimers(m_TimerInfos);
int displayCount = timerCount > MAX_DISPLAY_COUNT ? MAX_DISPLAY_COUNT : timerCount;
m_SectionTitleLabel.text = Utility.Text.Format("Active Timers ({0})", timerCount);

View File

@ -11,7 +11,7 @@ namespace AlicizaX.Timer.Runtime
public float CreationTime;
}
internal interface ITimerServiceDebugView
internal interface ITimerServiceDebug
{
int GetAllTimers(TimerDebugInfo[] results);

View File

@ -42,9 +42,7 @@ namespace AlicizaX.Timer.Runtime
public bool IsActive;
public byte HandlerType;
#if UNITY_EDITOR
public float CreationTime;
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
@ -64,16 +62,14 @@ namespace AlicizaX.Timer.Runtime
IsUnscaled = false;
IsActive = false;
HandlerType = 0;
#if UNITY_EDITOR
CreationTime = 0f;
#endif
}
}
[UnityEngine.Scripting.Preserve]
[Il2CppSetOption(Option.NullChecks, false)]
[Il2CppSetOption(Option.ArrayBoundsChecks, false)]
internal sealed class TimerService : ServiceBase, ITimerService, IServiceTickable, ITimerServiceDebugView
internal sealed class TimerService : ServiceBase, ITimerService, IServiceTickable, ITimerServiceDebug
{
private const int MAX_CAPACITY = 256;
private const int HANDLE_INDEX_BITS = 9;
@ -83,9 +79,7 @@ namespace AlicizaX.Timer.Runtime
private const byte HANDLER_NO_ARGS = 0;
private const byte HANDLER_GENERIC = 1;
#if UNITY_EDITOR
private const float LEAK_DETECTION_THRESHOLD = 300f;
#endif
private readonly TimerInfo[] _timerPool;
private readonly int[] _freeIndices;
@ -474,7 +468,7 @@ namespace AlicizaX.Timer.Runtime
public int Order => 0;
void ITimerServiceDebugView.GetStatistics(out int activeCount, out int poolCapacity, out int peakActiveCount, out int freeCount)
void ITimerServiceDebug.GetStatistics(out int activeCount, out int poolCapacity, out int peakActiveCount, out int freeCount)
{
activeCount = _activeCount;
poolCapacity = MAX_CAPACITY;
@ -482,7 +476,7 @@ namespace AlicizaX.Timer.Runtime
freeCount = _freeCount;
}
int ITimerServiceDebugView.GetAllTimers(TimerDebugInfo[] results)
int ITimerServiceDebug.GetAllTimers(TimerDebugInfo[] results)
{
if (results == null || results.Length == 0)
{
@ -501,8 +495,7 @@ namespace AlicizaX.Timer.Runtime
return count;
}
#if UNITY_EDITOR
int ITimerServiceDebugView.GetStaleOneShotTimers(TimerDebugInfo[] results)
int ITimerServiceDebug.GetStaleOneShotTimers(TimerDebugInfo[] results)
{
if (results == null || results.Length == 0)
{
@ -534,7 +527,6 @@ namespace AlicizaX.Timer.Runtime
return count;
}
#endif
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int AcquireTimerIndex()
@ -570,9 +562,7 @@ namespace AlicizaX.Timer.Runtime
timer.IsActive = true;
timer.HandlerType = HANDLER_NO_ARGS;
#if UNITY_EDITOR
timer.CreationTime = Time.realtimeSinceStartup;
#endif
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -786,9 +776,7 @@ namespace AlicizaX.Timer.Runtime
info.IsLoop = timer.IsLoop;
info.IsRunning = timer.IsRunning;
info.IsUnscaled = timer.IsUnscaled;
#if UNITY_EDITOR
info.CreationTime = timer.CreationTime;
#endif
}
}
}