Add Hunter/Hider role selection on connect with role-scoped modes

Roles are chosen in the bootstrap dev panel before Host/Client. NGO
ConnectionApproval is enabled at runtime and maps the role payload to
the matching prefab variant per connection (Hunter/Hider), so each peer
spawns the correct avatar including the host.

- PlayerRole.cs (new): single source of truth enum { Hider, Hunter }.
- NetworkBootstrap.cs: role toggle, ConnectionApproval + role payload,
  server ApprovalCheck mapping role -> PrefabIdHash.
- NetworkPlayerSetup.cs: serialized PlayerRole field + Role property.
- GameModeManager.cs: BuildModes(role) - Hunter -> [First Person, Paint],
  Hider -> [Third Person, Paint, Free Cam]; binds role from spawned avatar.
- Hunter.prefab: role = Hunter override.
- SampleScene.unity: NetworkBootstrap prefab references wired.

Also includes user inspector scale tuning (Hunter 2.5->2.4, Hider 0.5->0.7).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 4.8 committed 2026-06-27 17:01:43 +02:00
1 parent dec537a60f
commit 56caa0edd8
8 files changed
+138 -47

No files matched your search

+40 -26
View File
@@ -6,9 +6,10 @@ using UnityEngine.InputSystem;
#endif
/// <summary>
/// Switches the game between high-level modes (Player Control, Paint, Free Cam). The switch
/// key (Tab) cycles to the next registered mode. Register additional modes in
/// <see cref="BuildModes"/>. Attach to a single, persistent scene GameObject.
/// Switches the game between high-level modes. The switch key (Tab) cycles to the next registered
/// mode. The mode set is scoped to the local avatar's <see cref="PlayerRole"/> when it spawns
/// (Hunter: First Person + Paint; Hider: Player Control + Paint + Free Cam); a non-networked scene
/// uses the full set. Attach to a single, persistent scene GameObject.
/// </summary>
[DisallowMultipleComponent]
public class GameModeManager : MonoBehaviour
@@ -86,30 +87,40 @@ public class GameModeManager : MonoBehaviour
SwitchTo(Mathf.Clamp(startModeIndex, 0, _modes.Count - 1));
}
/// <summary>Registers all available modes. Add new modes here.</summary>
private void BuildModes()
/// <summary>Registers the modes for the current context. Without a role (no networked avatar yet,
/// or a non-networked scene) the full set is built from whichever rigs are present. With a role the
/// set is scoped to that side and ordered so index 0 is its intended start mode. Add new modes here.</summary>
private void BuildModes() => BuildModes(null);
private void BuildModes(PlayerRole? role)
{
_modes.Clear();
// Player Control only joins the Tab cycle when a gravity player is present, so a scene
// running only the insect walker doesn't trap input in a dead, player-freezing mode.
if (player)
_modes.Add(new PlayerControlMode());
switch (role)
{
case PlayerRole.Hunter:
// Hunter: first person + paint. Index 0 (First Person, if its rig exists) is the start mode.
if (firstPerson) _modes.Add(new FirstPersonMode());
_modes.Add(new PaintMode());
break;
_modes.Add(new PaintMode());
case PlayerRole.Hider:
// Hider: third person (player control) + paint + free cam. Index 0 (Player Control) is the start.
if (player) _modes.Add(new PlayerControlMode());
_modes.Add(new PaintMode());
if (freeCam) _modes.Add(new FreeCamMode());
break;
// Free Cam only joins the cycle when a freecam rig is present, so scenes without one are unchanged.
if (freeCam)
_modes.Add(new FreeCamMode());
// First Person only joins the cycle when a first-person rig is present, so scenes without one are unchanged.
if (firstPerson)
_modes.Add(new FirstPersonMode());
// Insect mode only joins the Tab cycle when a surface walker is present, so a scene
// without one behaves exactly as before (no dead, player-freezing mode in the cycle).
//if (insect)
// _modes.Add(new InsectMode());
default:
// No role: legacy full set, gated on whichever rigs exist. Player Control only joins when a
// gravity player is present (player-less pre-spawn stays in Paint, not a dead frozen mode);
// Free Cam / First Person only when their rigs exist, so non-networked scenes are unchanged.
if (player) _modes.Add(new PlayerControlMode());
_modes.Add(new PaintMode());
if (freeCam) _modes.Add(new FreeCamMode());
if (firstPerson) _modes.Add(new FirstPersonMode());
break;
}
foreach (var m in _modes)
m.Bind(this);
@@ -142,13 +153,16 @@ public class GameModeManager : MonoBehaviour
if (firstPerson)
firstPerson.SetPlayer(localPlayer);
// Tear down the pre-spawn (player-less) mode and rebuild with Player Control available.
// Tear down the pre-spawn (player-less) mode and rebuild scoped to this avatar's role.
ActiveMode?.Exit();
_activeIndex = -1;
BuildModes();
int idx = _modes.FindIndex(m => m is PlayerControlMode);
SwitchTo(idx >= 0 ? idx : Mathf.Clamp(startModeIndex, 0, _modes.Count - 1));
var setup = localPlayer.GetComponent<NetworkPlayerSetup>();
PlayerRole role = setup ? setup.Role : PlayerRole.Hider;
BuildModes(role);
// Each role list is ordered so index 0 is its start mode (Hunter -> First Person, Hider -> Player Control).
SwitchTo(0);
}
private void Update()