Files
Cielonos/Assets/Scripts/MainGame/Managers/MainGameManager.cs

98 lines
2.9 KiB
C#
Raw Normal View History

2025-12-22 18:36:29 -05:00
using System;
2026-02-13 09:22:11 -05:00
using Cielonos.Core;
2025-11-25 08:19:33 -05:00
using Cielonos.MainGame.Characters;
2026-02-13 09:22:11 -05:00
using SLSUtilities.General;
2026-05-10 11:47:55 -04:00
using SLSUtilities.UI;
2025-11-25 08:19:33 -05:00
using UnityEngine;
2026-03-20 12:07:44 -04:00
using UnityEngine.InputSystem;
2026-02-13 09:22:11 -05:00
using UnityEngine.Serialization;
2025-11-25 08:19:33 -05:00
namespace Cielonos.MainGame
{
public partial class MainGameManager : Singleton<MainGameManager>
{
public Player player;
2026-02-13 09:22:11 -05:00
public MainGameBaseCollection baseCollection;
2026-05-10 11:47:55 -04:00
public MainGameConfig mainGameConfig;
2025-11-25 08:19:33 -05:00
protected override void Awake()
{
base.Awake();
2025-12-22 18:36:29 -05:00
}
private void Start()
{
2026-03-20 12:07:44 -04:00
Application.targetFrameRate = 120;
2026-05-10 11:47:55 -04:00
// 订阅 UIPageManager 的输入阻塞事件,联动 isCursorLocked
if (UIPageManager.Instance != null)
{
UIPageManager.Instance.OnInputBlockChanged += OnUIInputBlockChanged;
}
// 场景加载完成后自动开始新一局 Run
RunManager.Instance.StartNewRun();
2025-11-25 08:19:33 -05:00
}
2025-12-23 19:47:06 -05:00
private void Update()
{
2026-05-10 11:47:55 -04:00
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame)
2025-12-23 19:47:06 -05:00
{
2026-05-10 11:47:55 -04:00
// 优先:如果有 UI 页面打开ESC 关闭栈顶页面
if (UIPageManager.Instance != null && UIPageManager.Instance.HasOpenPages)
{
UIPageManager.Instance.CloseTopPage();
return;
}
#if !UNITY_EDITOR
// 无页面打开时的 fallback切换鼠标锁定状态仅 Build
2026-03-20 12:07:44 -04:00
if (Cursor.lockState == CursorLockMode.Locked)
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
else
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
#endif
2026-05-10 11:47:55 -04:00
}
}
private void OnDestroy()
{
if (UIPageManager.Instance != null)
{
UIPageManager.Instance.OnInputBlockChanged -= OnUIInputBlockChanged;
}
}
/// <summary>
/// UIPageManager 输入阻塞回调。
/// blocked = true有页面打开 → 解锁鼠标,禁用游戏输入。
/// blocked = false所有页面关闭 → 锁定鼠标,恢复游戏输入。
/// </summary>
private void OnUIInputBlockChanged(bool blocked)
{
player.inputSc.isCursorLocked.Value = !blocked;
2025-12-23 19:47:06 -05:00
}
2025-11-25 08:19:33 -05:00
}
public partial class MainGameManager
{
public static Player Player => Instance.player;
2026-05-10 11:47:55 -04:00
public static AttributeSubmodule GlobalAttributeSm => Player.globalAttributeSm;
2026-02-13 09:22:11 -05:00
public static MainGameBaseCollection BaseCollection => Instance.baseCollection;
2026-05-10 11:47:55 -04:00
public static MainGameConfig Config => Instance.mainGameConfig;
public static string Seed;
2025-11-25 08:19:33 -05:00
}
}
namespace Cielonos.MainGame
{
}