1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-25 16:34:17 +00:00
better-tee/Assets/Packages/Mirror/Runtime/NetworkManagerHUD.cs
2019-09-17 17:43:32 +02:00

128 lines
4.4 KiB
C#

// vis2k: GUILayout instead of spacey += ...; removed Update hotkeys to avoid
// confusion if someone accidentally presses one.
using System.ComponentModel;
using UnityEngine;
namespace Mirror
{
/// <summary>
/// An extension for the NetworkManager that displays a default HUD for controlling the network state of the game.
/// <para>This component also shows useful internal state for the networking system in the inspector window of the editor. It allows users to view connections, networked objects, message handlers, and packet statistics. This information can be helpful when debugging networked games.</para>
/// </summary>
[AddComponentMenu("Network/NetworkManagerHUD")]
[RequireComponent(typeof(NetworkManager))]
[EditorBrowsable(EditorBrowsableState.Never)]
[HelpURL("https://mirror-networking.com/xmldocs/articles/Components/NetworkManagerHUD.html")]
public class NetworkManagerHUD : MonoBehaviour
{
NetworkManager manager;
/// <summary>
/// Whether to show the default control HUD at runtime.
/// </summary>
public bool showGUI = true;
/// <summary>
/// The horizontal offset in pixels to draw the HUD runtime GUI at.
/// </summary>
public int offsetX;
/// <summary>
/// The vertical offset in pixels to draw the HUD runtime GUI at.
/// </summary>
public int offsetY;
void Awake()
{
manager = GetComponent<NetworkManager>();
}
void OnGUI()
{
if (!showGUI)
return;
GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999));
if (!NetworkClient.isConnected && !NetworkServer.active)
{
if (!NetworkClient.active)
{
// LAN Host
if (Application.platform != RuntimePlatform.WebGLPlayer)
{
if (GUILayout.Button("LAN Host"))
{
manager.StartHost();
}
}
// LAN Client + IP
GUILayout.BeginHorizontal();
if (GUILayout.Button("LAN Client"))
{
manager.StartClient();
}
manager.networkAddress = GUILayout.TextField(manager.networkAddress);
GUILayout.EndHorizontal();
// LAN Server Only
if (Application.platform == RuntimePlatform.WebGLPlayer)
{
// cant be a server in webgl build
GUILayout.Box("( WebGL cannot be server )");
}
else
{
if (GUILayout.Button("LAN Server Only")) manager.StartServer();
}
}
else
{
// Connecting
GUILayout.Label("Connecting to " + manager.networkAddress + "..");
if (GUILayout.Button("Cancel Connection Attempt"))
{
manager.StopClient();
}
}
}
else
{
// server / client status message
if (NetworkServer.active)
{
GUILayout.Label("Server: active. Transport: " + Transport.activeTransport);
}
if (NetworkClient.isConnected)
{
GUILayout.Label("Client: address=" + manager.networkAddress);
}
}
// client ready
if (NetworkClient.isConnected && !ClientScene.ready)
{
if (GUILayout.Button("Client Ready"))
{
ClientScene.Ready(NetworkClient.connection);
if (ClientScene.localPlayer == null)
{
ClientScene.AddPlayer();
}
}
}
// stop
if (NetworkServer.active || NetworkClient.isConnected)
{
if (GUILayout.Button("Stop"))
{
manager.StopHost();
}
}
GUILayout.EndArea();
}
}
}