AlicizaX/Client/Assets/TimerBugTest.cs
2026-04-24 20:50:35 +08:00

54 lines
1.5 KiB
C#

using AlicizaX;
using AlicizaX.Timer.Runtime;
using UnityEngine;
public sealed class TimerBugTest : MonoBehaviour
{
private ITimerService _timerService;
private void Start()
{
_timerService = AppServices.Require<ITimerService>();
Debug.Log("=== Timer Bug Test Started ===");
TestNormalOnceTimer();
TestStopInCallback();
TestRemoveInCallback();
}
private void TestNormalOnceTimer()
{
Debug.Log("[Test 1] Creating normal once timer (1 second)...");
_timerService.AddTimer(OnNormalOnceTimer, 1f, isLoop: false);
}
private void TestStopInCallback()
{
Debug.Log("[Test 2] Creating once timer that calls Stop() in callback (2 seconds)...");
int timerId = 0;
timerId = _timerService.AddTimer(() =>
{
Debug.Log("[Test 2] Timer callback executed, calling Stop()...");
_timerService.Stop(timerId);
}, 2f, isLoop: false);
}
private void TestRemoveInCallback()
{
Debug.Log("[Test 3] Creating once timer that calls RemoveTimer() in callback (3 seconds)...");
int timerId = 0;
timerId = _timerService.AddTimer(() =>
{
Debug.Log("[Test 3] Timer callback executed, calling RemoveTimer()...");
_timerService.RemoveTimer(timerId);
}, 3f, isLoop: false);
}
private static void OnNormalOnceTimer()
{
Debug.Log("[Test 1] Timer callback executed!");
}
}