From 59a974ddeb421507e84a0a1ee938cd7cc70a51b0 Mon Sep 17 00:00:00 2001 From: habhab783124-lab Date: Tue, 15 Sep 2026 01:17:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E5=9C=BA=E6=99=AF=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/WorldMap/WorldMap_Main.unity | 2 +- .../Core/SceneFlow/SceneFlowService.cs | 25 ++++++- .../ApartmentKeepsake/SceneSwitchButton.cs | 66 +++++++++++++++++-- .../WorldMapSceneInteractionRouter.cs | 28 ++++++-- 4 files changed, 110 insertions(+), 11 deletions(-) diff --git a/Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity b/Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity index eb38fa0e..52fb21e2 100644 --- a/Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity +++ b/Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity @@ -19177,7 +19177,7 @@ RectTransform: m_GameObject: {fileID: 166605679} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 341065922} diff --git a/Assets/_Project/Scripts/Core/SceneFlow/SceneFlowService.cs b/Assets/_Project/Scripts/Core/SceneFlow/SceneFlowService.cs index c4c36d0c..e4ab7046 100644 --- a/Assets/_Project/Scripts/Core/SceneFlow/SceneFlowService.cs +++ b/Assets/_Project/Scripts/Core/SceneFlow/SceneFlowService.cs @@ -50,9 +50,27 @@ public SceneFlowService(ISceneCatalog catalog, EventBus eventBus, Func { + Application.backgroundLoadingPriority = previousBackgroundLoadingPriority; CurrentScene = target; IsLoading = false; + float elapsedSeconds = UnityEngine.Time.realtimeSinceStartup - startedAt; + Debug.Log( + $"[SceneFlow][LoadComplete] from={from} target={target} scene={sceneName} " + + $"elapsedSeconds={elapsedSeconds:F3}"); _eventBus.Publish(new SceneLoadCompletedEvent(from, target, payload)); onCompleted?.Invoke(); }; diff --git a/Assets/_Project/Scripts/Modules/ApartmentKeepsake/SceneSwitchButton.cs b/Assets/_Project/Scripts/Modules/ApartmentKeepsake/SceneSwitchButton.cs index fc0e0f7b..4a624f9d 100644 --- a/Assets/_Project/Scripts/Modules/ApartmentKeepsake/SceneSwitchButton.cs +++ b/Assets/_Project/Scripts/Modules/ApartmentKeepsake/SceneSwitchButton.cs @@ -1,5 +1,8 @@ +#nullable enable +using System; +using GeminiLab.Core; +using GeminiLab.Core.SceneFlow; using UnityEngine; -using UnityEngine.SceneManagement; public class SceneSwitchButton : MonoBehaviour { @@ -25,12 +28,65 @@ public void SwitchScene() return; } + if (!TryResolveSceneId(targetSceneName, out SceneId targetScene)) + { + Debug.LogError( + $"[SceneSwitchButton] 目标场景未登记到 SceneCatalog:{targetSceneName}", + this + ); + return; + } + + if (!ServiceLocator.TryResolve(out ISceneFlowService? sceneFlow) || sceneFlow is null) + { + Debug.LogError("[SceneSwitchButton] 未找到 ISceneFlowService", this); + return; + } + isLoading = true; + Debug.Log($"[SceneSwitchButton] 通过 SceneFlow 请求场景:{targetScene}", this); - Debug.Log( - $"[SceneSwitchButton] Loading scene: {targetSceneName}" - ); + try + { + AsyncOperation? operation = sceneFlow.LoadAsync( + targetScene, + onCompleted: HandleSceneLoadCompleted); + + if (operation is null) + { + isLoading = false; + Debug.LogWarning( + $"[SceneSwitchButton] 场景请求未启动:{targetScene}(可能已有加载进行中或目标已是当前场景)", + this + ); + } + } + catch (Exception exception) + { + isLoading = false; + Debug.LogException(exception, this); + } + } + + private void HandleSceneLoadCompleted() + { + isLoading = false; + } + + private static bool TryResolveSceneId(string sceneName, out SceneId sceneId) + { + sceneId = sceneName switch + { + "Boot" => SceneId.Boot, + "MainMenu" => SceneId.MainMenu, + "Prologue" => SceneId.Prologue, + "Apartment_Main" => SceneId.Apartment, + "WorldMap_Main" => SceneId.WorldMap, + "Desktop_Overlay" => SceneId.DesktopOverlay, + _ => default + }; - SceneManager.LoadScene(targetSceneName); + return sceneName is "Boot" or "MainMenu" or "Prologue" or "Apartment_Main" + or "WorldMap_Main" or "Desktop_Overlay"; } } diff --git a/Assets/_Project/Scripts/Modules/WorldMap/WorldMapSceneInteractionRouter.cs b/Assets/_Project/Scripts/Modules/WorldMap/WorldMapSceneInteractionRouter.cs index 9fbc06ef..7b369640 100644 --- a/Assets/_Project/Scripts/Modules/WorldMap/WorldMapSceneInteractionRouter.cs +++ b/Assets/_Project/Scripts/Modules/WorldMap/WorldMapSceneInteractionRouter.cs @@ -166,10 +166,30 @@ private static bool IsUiRaycastTarget(RaycastResult result) return false; } - // RaycastTarget is the UI input contract. A transparent Graphic can - // intentionally be an authored panel blocker, so alpha/culling must - // not allow the same click to fall through to a WorldMap object. - return true; + // Only interactive controls and open modal panels block WorldMap. + // Decorative HUD text/graphics must not swallow a click on the cabin. + if (hit.GetComponentInParent(true) != null) + { + return true; + } + + return IsUnderActiveModalPanel(hit); + } + + private static bool IsUnderActiveModalPanel(GameObject hit) + { + Transform? current = hit.transform; + while (current != null) + { + if (current.name.StartsWith("Panel_", StringComparison.Ordinal)) + { + return current.gameObject.activeInHierarchy; + } + + current = current.parent; + } + + return false; } private static bool InvokeTarget(IWorldMapSceneClickTarget target)