(Feat) Add Network Body
This commit is contained in:
@@ -38,6 +38,10 @@ namespace Ashwild.Network
|
||||
[Tooltip("The networked player prefab (NetworkObject + PlayerNetworkController).")]
|
||||
[SerializeField] private NetworkObject playerPrefab;
|
||||
|
||||
[Tooltip("Hard cap on total players in a room (host included). The transport is set to accept " +
|
||||
"maxPlayers - 1 remote clients, and the Steam invite lobby mirrors this limit.")]
|
||||
[SerializeField] private int maxPlayers = 6;
|
||||
|
||||
[Header("Debug")]
|
||||
[Tooltip("Logs every host/join/connection/spawn step to the console.")]
|
||||
[SerializeField] private bool verboseLogging = true;
|
||||
@@ -56,6 +60,12 @@ namespace Ashwild.Network
|
||||
/// </summary>
|
||||
public string GameSceneName => gameSceneName;
|
||||
|
||||
/// <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.
|
||||
/// </summary>
|
||||
public int MaxPlayers => maxPlayers;
|
||||
|
||||
/// <summary>
|
||||
/// Cached FishNet manager resolved from the active scene.
|
||||
/// </summary>
|
||||
@@ -262,6 +272,8 @@ namespace Ashwild.Network
|
||||
|
||||
if (args.ConnectionState == LocalConnectionState.Started)
|
||||
{
|
||||
ApplyPlayerCap();
|
||||
|
||||
string code = GetLocalSteamCode();
|
||||
PlayerEvents.RaiseSessionStarted(code);
|
||||
Log($"✅ Session créée ! Code à partager = {code}");
|
||||
@@ -430,6 +442,20 @@ namespace Ashwild.Network
|
||||
PlayerEvents.RaiseMenuReady();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Caps the transport at <see cref="maxPlayers"/> - 1 remote clients. Called once the server has
|
||||
/// Started, not before: FishySteamworks re-applies its own serialized limit to the socket inside
|
||||
/// StartConnection, so an earlier call would be clobbered. The host runs a local client that never
|
||||
/// crosses the Steam socket, so the remote limit is one below the total headcount; the transport
|
||||
/// then refuses the surplus connection outright.
|
||||
/// </summary>
|
||||
private void ApplyPlayerCap()
|
||||
{
|
||||
int remoteCap = Mathf.Max(0, maxPlayers - 1);
|
||||
networkManager.TransportManager.Transport.SetMaximumClients(remoteCap);
|
||||
Log($"Player cap set to {maxPlayers} (transport accepts {remoteCap} remote clients).");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the gameplay scene as a global networked scene, replacing the menu.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user