(Feat) Add Build
This commit is contained in:
@@ -30,6 +30,10 @@ namespace Ashwild.Network
|
||||
[Tooltip("The single source of truth for the gameplay scene loaded over the network.")]
|
||||
[SerializeField] private string gameSceneName = "TestScene";
|
||||
|
||||
[Tooltip("The single source of truth for the main menu scene, loaded on return-to-menu — both " +
|
||||
"the deliberate Quit and an involuntary disconnect (the host left / connection lost).")]
|
||||
[SerializeField] private string menuSceneName = "MenuScene";
|
||||
|
||||
[Tooltip("Max seconds to wait for the loading curtain to fully fade in before loading the game " +
|
||||
"scene anyway. Safety net so a missing/disabled LoadingScreen can never soft-lock the host.")]
|
||||
[SerializeField] private float curtainWaitTimeout = 3f;
|
||||
@@ -60,6 +64,11 @@ namespace Ashwild.Network
|
||||
/// </summary>
|
||||
public string GameSceneName => gameSceneName;
|
||||
|
||||
/// <summary>
|
||||
/// The main menu scene name (single source of truth, read by anything that needs it).
|
||||
/// </summary>
|
||||
public string MenuSceneName => menuSceneName;
|
||||
|
||||
/// <summary>
|
||||
/// Hard cap on total players per room (host included). Single source of truth for the
|
||||
/// player limit — the Steam invite lobby reads this to mirror the cap.
|
||||
@@ -82,6 +91,12 @@ namespace Ashwild.Network
|
||||
/// </summary>
|
||||
private bool curtainShown;
|
||||
|
||||
/// <summary>
|
||||
/// True while a return-to-menu transition is in flight, so the client-disconnect handler does
|
||||
/// not fire a second, redundant return on top of the deliberate one it triggers itself.
|
||||
/// </summary>
|
||||
private bool returningToMenu;
|
||||
|
||||
/// <summary>
|
||||
/// Round-robin cursor over the available spawn points.
|
||||
/// </summary>
|
||||
@@ -244,16 +259,21 @@ namespace Ashwild.Network
|
||||
/// the host launch: it raises the curtain, waits for it to fully fade in (so the menu-load freeze
|
||||
/// is hidden), tears the session down, loads the menu, then signals MenuReady to drop the curtain.
|
||||
/// Orchestrated here — not on the per-scene GameUIManager — because this object persists across
|
||||
/// the scene swap while the caller is destroyed by the load.
|
||||
/// the scene swap while the caller is destroyed by the load. Reused both for the deliberate Quit
|
||||
/// button and for an involuntary disconnect (the host left / connection lost); the re-entrancy
|
||||
/// guard makes the two paths converge on a single transition.
|
||||
/// </summary>
|
||||
public void ReturnToMenu(string menuSceneName)
|
||||
public void ReturnToMenu()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(menuSceneName))
|
||||
{
|
||||
Debug.LogError("[NetworkSession] ReturnToMenu called with no menu scene name.", this);
|
||||
Debug.LogError("[NetworkSession] ReturnToMenu called but no menu scene name is assigned.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (returningToMenu) return;
|
||||
returningToMenu = true;
|
||||
|
||||
PlayerEvents.RaiseReturningToMenu();
|
||||
curtainShown = false;
|
||||
StartCoroutine(ReturnToMenuRoutine(menuSceneName));
|
||||
@@ -295,6 +315,13 @@ namespace Ashwild.Network
|
||||
/// <summary>
|
||||
/// Local client transport changed state. For a pure client (join) this drives the
|
||||
/// joined/stopped bus events; for a host the server handler already covers it.
|
||||
///
|
||||
/// On Stopped it also rescues a client dropped while in-game — the host quit or the connection
|
||||
/// was lost — by driving it back to the menu through the same curtained transition as the Quit
|
||||
/// button. Without this the client would sit stranded in the now-dead game scene. The guard
|
||||
/// skips this when a deliberate return is already in flight (the Quit button's own teardown
|
||||
/// stops the client too) and when we never made it into the game scene (a failed join, which
|
||||
/// the session-error flow already handles), so the menu is never reloaded needlessly.
|
||||
/// </summary>
|
||||
private void HandleClientState(ClientConnectionStateArgs args)
|
||||
{
|
||||
@@ -311,6 +338,12 @@ namespace Ashwild.Network
|
||||
else if (args.ConnectionState == LocalConnectionState.Stopped)
|
||||
{
|
||||
PlayerEvents.RaiseSessionStopped();
|
||||
|
||||
if (!returningToMenu && UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == gameSceneName)
|
||||
{
|
||||
Log("Client disconnected while in-game (host left / connection lost) — returning to menu.");
|
||||
ReturnToMenu();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -439,6 +472,7 @@ namespace Ashwild.Network
|
||||
Debug.LogError($"[NetworkSession] Could not load menu scene '{menuSceneName}' — is it in Build Settings?", this);
|
||||
}
|
||||
|
||||
returningToMenu = false;
|
||||
PlayerEvents.RaiseMenuReady();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user