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

113 lines
3.6 KiB
C#
Raw Normal View History

2026-06-02 12:55:39 -04:00
using Cielonos.Core.UI;
2025-11-25 08:19:33 -05:00
using Cielonos.MainGame.Characters;
2026-06-02 12:55:39 -04:00
using DG.Tweening;
using Sirenix.OdinInspector;
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-06-02 12:55:39 -04:00
using UnityEngine.SceneManagement;
2025-11-25 08:19:33 -05:00
namespace Cielonos.MainGame
{
public partial class MainGameManager : Singleton<MainGameManager>
{
2026-06-02 12:55:39 -04:00
[SerializeField]
private Player player;
[SerializeField]
private MainGameBaseCollection baseCollection;
[SerializeField]
private MainGameConfig mainGameConfig;
[Title("Submodules")] public SceneSubmodule sceneSm;
2025-11-25 08:19:33 -05:00
protected override void Awake()
{
base.Awake();
2026-06-02 12:55:39 -04:00
sceneSm = new SceneSubmodule(this);
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;
}
2026-06-02 12:55:39 -04:00
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();
}
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
}
}