using Cielonos.Core.UI; using Cielonos.MainGame.Characters; using DG.Tweening; using Sirenix.OdinInspector; using SLSUtilities.General; using SLSUtilities.UI; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.SceneManagement; namespace Cielonos.MainGame { public partial class MainGameManager : Singleton { [SerializeField] private Player player; [SerializeField] private MainGameBaseCollection baseCollection; [SerializeField] private MainGameConfig mainGameConfig; [Title("Submodules")] public SceneSubmodule sceneSm; protected override void Awake() { base.Awake(); sceneSm = new SceneSubmodule(this); } private void Start() { Application.targetFrameRate = 120; // 订阅 UIPageManager 的输入阻塞事件,联动 isCursorLocked if (UIPageManager.Instance != null) { UIPageManager.Instance.OnInputBlockChanged += OnUIInputBlockChanged; } if (sceneSm.IsCityArena) { RunManager.Instance.StartNewRun(); sceneSm.cityArenaBeginningProcessor.Process(); } else if (sceneSm.IsFortress) { // 基地场景不需要 RunManager,直接锁定鼠标并开启移动输入 if (player != null && player.inputSc != null) { player.inputSc.isCursorLocked.Value = true; } // 播放淡入动画(如果有 ScreenFader 的话) ScreenFader.Instance?.FadeToClear().Play(); } } private void Update() { if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame) { // 优先:如果有 UI 页面打开,ESC 关闭栈顶页面 if (UIPageManager.Instance != null && UIPageManager.Instance.HasOpenPages) { UIPageManager.Instance.CloseTopPage(); return; } #if !UNITY_EDITOR // 无页面打开时的 fallback:切换鼠标锁定状态(仅 Build) if (Cursor.lockState == CursorLockMode.Locked) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } else { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } #endif } } private void OnDestroy() { if (UIPageManager.Instance != null) { UIPageManager.Instance.OnInputBlockChanged -= OnUIInputBlockChanged; } } /// /// UIPageManager 输入阻塞回调。 /// blocked = true:有页面打开 → 解锁鼠标,禁用游戏输入。 /// blocked = false:所有页面关闭 → 锁定鼠标,恢复游戏输入。 /// private void OnUIInputBlockChanged(bool blocked) { player.inputSc.isCursorLocked.Value = !blocked; } } public partial class MainGameManager { public static Player Player => Instance.player; public static AttributeSubmodule GlobalAttributeSm => Player.globalAttributeSm; public static MainGameBaseCollection BaseCollection => Instance.baseCollection; public static MainGameConfig Config => Instance.mainGameConfig; public static string Seed; } }