Replace the connection-approval role selection with a server-authoritative match flow built on NGO additive scene management: - Scenes: Main is the persistent foundation (NetworkManager, GameModeManager, cameras, HUD); Lobby and Test Map load/unload additively. Add Lobby + Test Map to the build settings; remove the obsolete SampleScene. - MatchManager (plain MonoBehaviour singleton): loads Lobby on server start, StartMatchTrigger lets the host start the match, rolls one random Hunter (rest Hider), swaps Lobby -> Test Map (strictly serialized per NGO), respawns each player as its role variant. Forces additive client sync mode so clients keep Main instead of single-loading it (fixes "Destination scene is not valid"). - Server-driven spawning: null out NetworkConfig.PlayerPrefab at runtime to disable auto-spawn, then spawn players after the lobby floor exists (fixes falling through the floor) with double-spawn and transition guards. - StartMatchTrigger: server-gated OnTriggerEnter, only the host's own player starts the match. - NetworkBootstrap: drop role selection / connection approval; everyone spawns as the neutral Player prefab. Host/Client/Server/Shutdown buttons stay. - NetworkPlayerSetup.ScopedModes flag (baked on Hunter/Hider prefabs): lobby avatar gets the full mode set, match variants get the role-scoped set. - GameModeManager.BindLocalPlayer reads ScopedModes and rebinds the painter unconditionally (fixes stale painter binding on respawn -> brush painting in every mode). - MeshPainter.PaintingEnabled defaults to false (unbound/pre-spawn/remote never paints); PaintHud visibility now also gates on a bound painter (fixes the HUD showing at startup before any avatar exists). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
2.5 KiB
C#
71 lines
2.5 KiB
C#
using Unity.Netcode;
|
|
using UnityEngine;
|
|
#if ENABLE_INPUT_SYSTEM
|
|
using UnityEngine.InputSystem;
|
|
#endif
|
|
|
|
/// <summary>
|
|
/// Dev-only connection harness for local multiplayer testing across the junction-mirror clones: one
|
|
/// instance clicks Host and the others click Client (loopback 127.0.0.1 via the configured
|
|
/// UnityTransport). Everyone spawns as the neutral Player prefab into the Lobby; roles (Hunter/Hider)
|
|
/// are rolled and applied by <see cref="MatchManager"/> when the match starts, not here. Hotkeys:
|
|
/// H = Host, C = Client, J = Server, K = Shutdown. Purely a testing scaffold - replace with real
|
|
/// lobby/menu UI later. Attach to the same GameObject as the NetworkManager.
|
|
/// </summary>
|
|
[RequireComponent(typeof(NetworkManager))]
|
|
[DisallowMultipleComponent]
|
|
public class NetworkBootstrap : MonoBehaviour
|
|
{
|
|
[Tooltip("Draw the on-screen Host/Client panel (top-left).")]
|
|
public bool showGui = true;
|
|
|
|
[Tooltip("Allow the H/C/J/K keyboard shortcuts.")]
|
|
public bool enableHotkeys = true;
|
|
|
|
private NetworkManager _net;
|
|
|
|
private void Awake() => _net = GetComponent<NetworkManager>();
|
|
|
|
private void Update()
|
|
{
|
|
if (!enableHotkeys) return;
|
|
#if ENABLE_INPUT_SYSTEM
|
|
var kb = Keyboard.current;
|
|
if (kb == null || _net == null) return;
|
|
if (!_net.IsListening)
|
|
{
|
|
if (kb.hKey.wasPressedThisFrame) _net.StartHost();
|
|
else if (kb.cKey.wasPressedThisFrame) _net.StartClient();
|
|
else if (kb.jKey.wasPressedThisFrame) _net.StartServer();
|
|
}
|
|
else if (kb.kKey.wasPressedThisFrame)
|
|
{
|
|
_net.Shutdown();
|
|
}
|
|
#endif
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (!showGui || _net == null) return;
|
|
|
|
GUILayout.BeginArea(new Rect(10, 10, 220, 160), GUI.skin.box);
|
|
if (!_net.IsListening)
|
|
{
|
|
GUILayout.Label("Netcode (dev)");
|
|
if (GUILayout.Button("Host (H)")) _net.StartHost();
|
|
if (GUILayout.Button("Client (C)")) _net.StartClient();
|
|
if (GUILayout.Button("Server (J)")) _net.StartServer();
|
|
}
|
|
else
|
|
{
|
|
string role = _net.IsHost ? "Host" : _net.IsServer ? "Server" : "Client";
|
|
GUILayout.Label($"Role: {role}");
|
|
GUILayout.Label($"ClientId: {_net.LocalClientId}");
|
|
GUILayout.Label($"Clients: {(_net.IsServer ? _net.ConnectedClients.Count : (_net.IsConnectedClient ? 1 : 0))}");
|
|
if (GUILayout.Button("Shutdown (K)")) _net.Shutdown();
|
|
}
|
|
GUILayout.EndArea();
|
|
}
|
|
}
|