2020-12-07 20:49:51 +00:00
|
|
|
|
using UnityEngine;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
2020-12-07 21:19:16 +00:00
|
|
|
|
namespace QuantumUNET.Components
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
public class QNetworkManagerHUD : MonoBehaviour
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
public QNetworkManager Manager;
|
|
|
|
|
public bool ShowGUI = true;
|
2020-12-08 09:03:10 +00:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
private void Awake()
|
|
|
|
|
=> Manager = GetComponent<QNetworkManager>();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
|
|
|
|
|
private void OnGUI()
|
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (ShowGUI)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
var xOffset = 10;
|
|
|
|
|
var yOffset = 30;
|
|
|
|
|
var flag = Manager.client == null || Manager.client.connection == null || Manager.client.connection.connectionId == -1;
|
|
|
|
|
if (!Manager.IsClientConnected() && !QNetworkServer.active)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (flag)
|
|
|
|
|
{
|
|
|
|
|
if (Application.platform != RuntimePlatform.WebGLPlayer)
|
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (GUI.Button(new Rect(xOffset, yOffset, 200f, 20f), "Host"))
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
Manager.StartHost();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (GUI.Button(new Rect(xOffset, yOffset, 105f, 20f), "Connect"))
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
Manager.StartClient();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
Manager.networkAddress = GUI.TextField(new Rect(xOffset + 100, yOffset, 95f, 20f), Manager.networkAddress);
|
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(xOffset, yOffset, 200f, 20f),
|
|
|
|
|
$"Connecting to {Manager.networkAddress}:{Manager.networkPort}..");
|
|
|
|
|
yOffset += 24;
|
|
|
|
|
if (GUI.Button(new Rect(xOffset, yOffset, 200f, 20f), "Cancel Connection Attempt"))
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
Manager.StopClient();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
if (QNetworkServer.active)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
var text = $"Hosting on port {Manager.networkPort}";
|
|
|
|
|
if (Manager.useWebSockets)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2020-12-07 20:47:07 +00:00
|
|
|
|
text += " (using WebSockets)";
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(xOffset, yOffset, 300f, 20f), text);
|
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (Manager.IsClientConnected())
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
GUI.Label(new Rect(xOffset, yOffset, 300f, 20f), $"Connected to {Manager.networkAddress}, port {Manager.networkPort}");
|
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (Manager.IsClientConnected() && !QClientScene.ready)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (GUI.Button(new Rect(xOffset, yOffset, 200f, 20f), "Client Ready"))
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
QClientScene.Ready(Manager.client.connection);
|
2020-12-23 12:58:45 +00:00
|
|
|
|
if (QClientScene.localPlayers.Count == 0)
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2020-12-23 12:58:45 +00:00
|
|
|
|
QClientScene.AddPlayer(0);
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (QNetworkServer.active || Manager.IsClientConnected())
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
if (GUI.Button(new Rect(xOffset, yOffset, 200f, 20f), "Stop"))
|
2020-12-02 18:40:38 +00:00
|
|
|
|
{
|
2021-02-21 18:25:25 +00:00
|
|
|
|
Manager.StopHost();
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
2021-06-18 22:39:21 +01:00
|
|
|
|
|
2021-02-21 18:25:25 +00:00
|
|
|
|
yOffset += 20;
|
2020-12-02 18:40:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|