using UnityEngine; namespace Aliciza.Services.Example { public sealed class ExampleBattleScopeController : MonoBehaviour { [SerializeField] private int _scopeOrder = 100; [SerializeField] private bool _toggleByInput = true; private ServiceScope _battleScope; public bool HasBattleScope => _battleScope != null && !_battleScope.IsDisposed; private void Update() { if (!_toggleByInput) return; if (!GameServices.TryGet(out var inputService)) return; if (!inputService.ToggleBattlePressedThisFrame) return; if (HasBattleScope) ExitBattle(); else EnterBattle(); } private void OnDestroy() { ExitBattle(); } [ContextMenu("Enter Battle")] public void EnterBattle() { if (HasBattleScope) return; if (!GameServices.HasWorld) { Debug.LogWarning("[ExampleBattleScopeController] Cannot create Battle scope: ServiceWorld does not exist."); return; } _battleScope = GameServices.CreateScope(_scopeOrder); _battleScope.Register(new BattleLoopService()); Debug.Log("[ExampleBattleScopeController] Created BattleScope."); } [ContextMenu("Exit Battle")] public void ExitBattle() { if (_battleScope == null) return; if (GameServices.HasWorld) GameServices.DestroyScope(); _battleScope = null; Debug.Log("[ExampleBattleScopeController] Destroyed BattleScope."); } } }