using System; using Cielonos.Core; using Cielonos.MainGame.Characters; using SLSUtilities.General; using SLSUtilities.UI; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.Serialization; namespace Cielonos.MainGame { public partial class MainGameManager : Singleton { public Player player; public MainGameBaseCollection baseCollection; public MainGameConfig mainGameConfig; protected override void Awake() { base.Awake(); } private void Start() { Application.targetFrameRate = 120; // 订阅 UIPageManager 的输入阻塞事件,联动 isCursorLocked if (UIPageManager.Instance != null) { UIPageManager.Instance.OnInputBlockChanged += OnUIInputBlockChanged; } // 场景加载完成后自动开始新一局 Run RunManager.Instance.StartNewRun(); } 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; } } namespace Cielonos.MainGame { }