using UnityEngine; namespace Aliciza.Services.Example { public sealed class BattleLoopService : ServiceBase, IBattleLoopService, IServiceTickable, IServiceOrder { private ITimerService _timerService; private int _pulseTimerId = -1; public float ElapsedTime { get; private set; } public int PulseCount { get; private set; } public int Order => 100; public void Tick(float deltaTime) { ElapsedTime += deltaTime; } protected override void OnInitialize() { ElapsedTime = 0f; PulseCount = 0; if (World.TryGet(out _timerService)) { _pulseTimerId = _timerService.Repeat(1f, OnPulse); } } protected override void OnDestroyService() { if (_timerService != null && _pulseTimerId > 0) { _timerService.Cancel(_pulseTimerId); } _pulseTimerId = -1; _timerService = null; ElapsedTime = 0f; PulseCount = 0; } private void OnPulse() { PulseCount++; Debug.Log($"[BattleLoopService] Pulse {PulseCount}, Elapsed={ElapsedTime:F2}"); } } }