Files
adminandClaude Fable 5 6c03e5d3f6 Refactor Assets/Scripts: trim restating comments, minor structure cleanups
Sweep over 48 files (Editor/ excluded): remove comments that restate the
code, condense class summaries, fix three stale doc statements
(HsvColorPicker alpha bar, PaintHud layoutPrefab, MasterVolume
FallbackDefault). Inline two single-use wrappers (IsPointerOverUi,
BuildModes), drop an unused using, replace a magic literal with the
existing ParallaxBase constant, and convert ~10 UnityEngine.Object null
checks to the implicit-bool convention. No serialized fields, signatures,
RPC/NetworkVariable names, defaults, or #if blocks touched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 08:29:18 +02:00

78 lines
2.4 KiB
C#

using Unity.Netcode;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
/// <summary>
/// Dev-only connection harness for local multiplayer testing: Host/Client/Server over loopback via the
/// configured UnityTransport (hotkeys H/C/J, K = Shutdown). Roles are rolled by <see cref="MatchManager"/>
/// at match start, not here. Testing scaffold only - replace with real lobby/menu UI later.
/// </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()
{
if (!Application.isEditor)
{
Destroy(this);
return;
}
_net = GetComponent<NetworkManager>();
}
private void Update()
{
if (!enableHotkeys) return;
if (TypingGuard.IsTyping) return; // don't fire H/C/J/K while typing in a text field
#if ENABLE_INPUT_SYSTEM
var kb = Keyboard.current;
if (kb == null || !_net) 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) 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();
}
}