Replace stripped-player spectator with a minimal dedicated prefab
Mid-match joiners now spawn a dedicated empty Spectator prefab (NetworkObject + SpectatorSetup only) instead of a fully stripped Player prefab. The FreeCam rig is a standalone scene object in Main, so the spectator needs no avatar body, renderer, collider, or CharacterController -- eliminating the leftover-body artifact and the fragile per-peer strip path entirely. - SpectatorSetup.cs (new): owner binds GameModeManager.BindSpectator (FreeCam-only) - Spectator.prefab (new): empty avatar (Transform + NetworkObject + SpectatorSetup), registered in DefaultNetworkPrefabs, wired on MatchManager in Main - GameModeManager: add BindSpectator/BuildSpectatorModes; drop the spectator branch from BindLocalPlayer; ReleaseToNoPlayer frees the cursor on teardown - MatchManager: independent entropy-seeded RNG for fair hunter pick (was sharing the global engine RNG and always landing on the same client); spawn the spectator prefab for mid-match joiners; cursor-safe return-to-Main teardown - FreeCamController: guard IgnorePlayerCollision against a disabled capsule Also bundled (unrelated user asset/UI edits): PaintHudPanel layout tuning, font atlas (arialroundedmtprocyr_bold SDF), forestpack_foliage material. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
be6db5b0a9
commit
91ce8ff329
12 files changed
+227
-1284
No files matched your search
@@ -126,6 +126,35 @@ public class GameModeManager : MonoBehaviour
|
||||
m.Bind(this);
|
||||
}
|
||||
|
||||
/// <summary>Spectator mode set for a mid-match joiner: free-fly camera only (no player control, no
|
||||
/// paint). They can fly around and watch, but not play, until the host ends the match (then they
|
||||
/// respawn as a neutral lobby Player). Falls back to nothing if the scene has no free-cam rig.</summary>
|
||||
private void BuildSpectatorModes()
|
||||
{
|
||||
_modes.Clear();
|
||||
if (freeCam) _modes.Add(new FreeCamMode());
|
||||
foreach (var m in _modes)
|
||||
m.Bind(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds a mid-match spectator. The spectator object is empty (no body/painter to bind), so just clear
|
||||
/// the player/painter and switch the cycle to free-cam-only. The free-cam rig is a separate persistent
|
||||
/// scene object that flies off Camera.main, so it needs nothing from the spectator. Called from
|
||||
/// <see cref="SpectatorSetup"/> on the owning client.
|
||||
/// </summary>
|
||||
public void BindSpectator()
|
||||
{
|
||||
player = null;
|
||||
painter = null;
|
||||
PainterChanged?.Invoke(null);
|
||||
|
||||
ActiveMode?.Exit();
|
||||
_activeIndex = -1;
|
||||
BuildSpectatorModes();
|
||||
SwitchTo(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Binds the scene singletons (this manager, the orbit/first-person cameras, the painter) to the
|
||||
/// locally-owned networked player after it spawns, then enters Player Control. Called from
|
||||
@@ -135,19 +164,21 @@ public class GameModeManager : MonoBehaviour
|
||||
public void BindLocalPlayer(PlayerCharacterController localPlayer)
|
||||
{
|
||||
if (!localPlayer) return;
|
||||
|
||||
var setup = localPlayer.GetComponent<NetworkPlayerSetup>();
|
||||
|
||||
player = localPlayer;
|
||||
|
||||
// The painter lives on the player (per-avatar), so bind the local one - UNCONDITIONALLY. On a
|
||||
// lobby->match respawn the previous avatar is despawned and the role variant spawned in the same
|
||||
// server frame; the old painter is Destroy-pending (still non-null) when this runs, so a
|
||||
// `if (!painter)` guard would keep the stale reference and the new avatar's painter would never be
|
||||
// mode-toggled - it would paint in every mode. Always re-point to the freshly spawned avatar.
|
||||
// mode-toggled - it would paint in every mode. Always re-point to the fresh avatar.
|
||||
painter = localPlayer.GetComponentInChildren<MeshPainter>(true);
|
||||
PainterChanged?.Invoke(painter);
|
||||
|
||||
// Point the cameras at the avatar's follow target.
|
||||
Transform camTarget = localPlayer.transform.Find("CameraTarget");
|
||||
|
||||
// Re-point the third-person orbit camera (Cinemachine Follow/LookAt) at the local avatar.
|
||||
if (cameraInput)
|
||||
{
|
||||
var vcam = cameraInput.GetComponent<CinemachineCamera>();
|
||||
@@ -161,9 +192,10 @@ public class GameModeManager : MonoBehaviour
|
||||
ActiveMode?.Exit();
|
||||
_activeIndex = -1;
|
||||
|
||||
// Lobby/neutral avatar (base Player prefab) -> full mode set; match avatar (Hunter/Hider
|
||||
// variant) -> only its role's modes. Baked per prefab, so no replicated-phase timing race.
|
||||
var setup = localPlayer.GetComponent<NetworkPlayerSetup>();
|
||||
// Lobby/neutral avatar (base Player prefab) -> full mode set; match avatar (Hunter/Hider variant)
|
||||
// -> only its role's modes. Scope is baked per prefab variant, so it follows the spawned avatar
|
||||
// with no replicated-phase timing race. (Mid-match spectators take a separate, empty prefab and
|
||||
// bind via BindSpectator, not here.)
|
||||
if (setup && setup.ScopedModes)
|
||||
BuildModes(setup.Role);
|
||||
else
|
||||
@@ -174,6 +206,31 @@ public class GameModeManager : MonoBehaviour
|
||||
SwitchTo(0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops back to a player-less state when the local avatar is gone (disconnect / server shutdown
|
||||
/// returns the session to the empty Main scene). Tears down the active mode so any FreeCam/First-Person
|
||||
/// camera takeover is undone (which unlocks the cursor), clears the mode cycle, and - crucially - parks
|
||||
/// the persistent orbit input in Disabled: it otherwise re-locks the cursor every frame while
|
||||
/// AlwaysActive, so a one-off unlock would be reverted next frame and the OS cursor would stay captured
|
||||
/// with no avatar to control. A reconnect's <see cref="BindLocalPlayer"/> restores everything.
|
||||
/// </summary>
|
||||
public void ReleaseToNoPlayer()
|
||||
{
|
||||
ActiveMode?.Exit();
|
||||
_activeIndex = -1;
|
||||
_modes.Clear();
|
||||
player = null;
|
||||
painter = null;
|
||||
PainterChanged?.Invoke(null);
|
||||
|
||||
if (cameraInput)
|
||||
cameraInput.LookMode = ThirdPersonOrbitInput.OrbitLookMode.Disabled;
|
||||
|
||||
// Belt-and-braces explicit release (covers the orbit input being absent/disabled).
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Cursor.visible = true;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_modes.Count == 0) return;
|
||||
|
||||
Reference in new issue
Block a user