Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/_Project/Scenes/WorldMap/WorldMap_Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
25 changes: 24 additions & 1 deletion Assets/_Project/Scripts/Core/SceneFlow/SceneFlowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,27 @@ public SceneFlowService(ISceneCatalog catalog, EventBus eventBus, Func<string, L
SceneId from = CurrentScene;
string sceneName = _catalog.GetSceneName(target);

AsyncOperation? op = _loader(sceneName, LoadSceneMode.Single);
UnityEngine.ThreadPriority previousBackgroundLoadingPriority = Application.backgroundLoadingPriority;
Application.backgroundLoadingPriority = UnityEngine.ThreadPriority.High;
float startedAt = UnityEngine.Time.realtimeSinceStartup;
Debug.Log(
$"[SceneFlow][LoadStart] from={from} target={target} scene={sceneName} " +
$"backgroundPriority={Application.backgroundLoadingPriority}");

AsyncOperation? op;
try
{
op = _loader(sceneName, LoadSceneMode.Single);
}
catch
{
Application.backgroundLoadingPriority = previousBackgroundLoadingPriority;
throw;
}

if (op is null)
{
Application.backgroundLoadingPriority = previousBackgroundLoadingPriority;
Debug.LogError($"[SceneFlow] 加载失败:{sceneName}(未登记在 Build Settings 或 catalog 错配)");
return null;
}
Expand All @@ -62,8 +80,13 @@ public SceneFlowService(ISceneCatalog catalog, EventBus eventBus, Func<string, L

op.completed += _ =>
{
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();
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#nullable enable
using System;
using GeminiLab.Core;
using GeminiLab.Core.SceneFlow;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneSwitchButton : MonoBehaviour
{
Expand All @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Selectable>(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)
Expand Down
Loading