地图系统
This commit is contained in:
81
Assets/_Game/Scripts/Editor/Debug/DebugEnterTestRoom.cs
Normal file
81
Assets/_Game/Scripts/Editor/Debug/DebugEnterTestRoom.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Assets;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Editor.Debugging
|
||||
{
|
||||
/// <summary>
|
||||
/// 调试入口:绕过尚在开发中的「新游戏 / 存档槽 / 模式选择」UI,
|
||||
/// 直接加载首关(<see cref="AddressKeys.SceneGameChapter1"/>,当前映射到 TestRoomA)并生成玩家,
|
||||
/// 便于在编辑器中快速验证游戏内系统(如地图)。
|
||||
/// <para>
|
||||
/// 复刻 <c>MainMenuController.HandleSlotConfirmed</c> 的核心动作:建立内存存档 + 发场景过渡请求。
|
||||
/// 仅在 Play 模式可用。
|
||||
/// </para>
|
||||
/// 菜单:BaseGames ▸ Debug ▸ Enter First Room (Play)
|
||||
/// </summary>
|
||||
public static class DebugEnterTestRoom
|
||||
{
|
||||
private const string MenuPath = "BaseGames/Debug/Enter First Room (Play)";
|
||||
|
||||
[MenuItem(MenuPath, priority = 900)]
|
||||
public static void EnterFirstRoom()
|
||||
{
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
Debug.LogWarning("[Debug] 请先进入 Play 模式再使用此入口。");
|
||||
return;
|
||||
}
|
||||
|
||||
var save = ServiceLocator.GetOrDefault<ISaveService>();
|
||||
if (save != null && !save.HasSave(0))
|
||||
save.CreateSlot(0, false); // 建立内存存档,确保新游戏初始状态
|
||||
|
||||
// 必须经事件频道 EVT_SceneLoadRequest 发请求:SceneService 据此加载场景,
|
||||
// GameManager 据此驱动状态机 LoadingScene → Gameplay(HUD/小地图随之显示)。
|
||||
// 直接调 ISceneService.RequestTransition 会绕过 GameManager 状态机,导致停留在 MainMenu、HUD 隐藏。
|
||||
var channel = FindSceneLoadChannel();
|
||||
if (channel == null)
|
||||
{
|
||||
Debug.LogError("[Debug] 未找到 EVT_SceneLoadRequest(SceneLoadRequestEventChannelSO)资产。");
|
||||
return;
|
||||
}
|
||||
|
||||
channel.Raise(new SceneLoadRequest
|
||||
{
|
||||
SceneName = AddressKeys.SceneGameChapter1, // 当前映射到 TestRoomA
|
||||
EntryTransitionId = null, // 默认出生点
|
||||
TransitionType = TransitionType.Scene,
|
||||
ShowLoadingScreen = true,
|
||||
IsRespawn = false,
|
||||
});
|
||||
|
||||
Debug.Log($"[Debug] 已经事件频道请求加载首关 '{AddressKeys.SceneGameChapter1}',将走 LoadingScene → Gameplay。");
|
||||
}
|
||||
|
||||
/// <summary>加载 EVT_SceneLoadRequest 频道资产(与 GameManager/SceneService 共享同一实例)。</summary>
|
||||
private static SceneLoadRequestEventChannelSO FindSceneLoadChannel()
|
||||
{
|
||||
foreach (var guid in AssetDatabase.FindAssets("t:SceneLoadRequestEventChannelSO"))
|
||||
{
|
||||
var path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var asset = AssetDatabase.LoadAssetAtPath<SceneLoadRequestEventChannelSO>(path);
|
||||
if (asset != null && asset.name == "EVT_SceneLoadRequest") return asset;
|
||||
}
|
||||
// 回退:任意同类型频道
|
||||
foreach (var guid in AssetDatabase.FindAssets("t:SceneLoadRequestEventChannelSO"))
|
||||
{
|
||||
var asset = AssetDatabase.LoadAssetAtPath<SceneLoadRequestEventChannelSO>(AssetDatabase.GUIDToAssetPath(guid));
|
||||
if (asset != null) return asset;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
[MenuItem(MenuPath, validate = true)]
|
||||
private static bool Validate() => Application.isPlaying;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user