69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
|
|
[NetworkSettings(channel = 0, sendInterval = 0)]
|
|
public class serverRunningMenu : NetworkBehaviour
|
|
{
|
|
public Text clientInfo;
|
|
public Text uptime;
|
|
public Text throughput;
|
|
|
|
private float startTime = 0;
|
|
private bool hasStarted = false;
|
|
|
|
public carCount carCounter;
|
|
public GameObject next;
|
|
public NetworkManager network;
|
|
|
|
private float timePassed = 0;
|
|
|
|
//WebGL-ben build hibát okozna.
|
|
#if UNITY_STANDALONE
|
|
public void Update ()
|
|
{
|
|
if (!hasStarted)
|
|
{
|
|
startTime = Time.time;
|
|
hasStarted = true;
|
|
}
|
|
|
|
if (timePassed < 1) timePassed += Time.deltaTime;
|
|
else
|
|
{
|
|
Debug.Log(NetworkServer.connections);
|
|
Debug.Log(NetworkServer.connections.Count);
|
|
|
|
timePassed = 0;
|
|
|
|
clientInfo.text = "Clients:\n";
|
|
foreach (NetworkConnection connection in NetworkServer.connections) {
|
|
if(connection != null)
|
|
{
|
|
/*int unused;
|
|
int bytesSent = 0;
|
|
connection.GetStatsOut(out unused, out unused, out bytesSent, out unused);*/
|
|
clientInfo.text += (connection.address.ToString() == "" ? "websocket connection" : connection.address.ToString()) + "\n";
|
|
}
|
|
}
|
|
|
|
throughput.text = "Cars passed: " + carCounter.throughput.ToString();
|
|
|
|
float timeInS = Time.time - startTime;
|
|
uptime.text = "Uptime: " + Mathf.Round(timeInS / 60 / 60).ToString() + "h " + Mathf.Round(timeInS % ( 60 * 60 ) / 60).ToString() + "m " + Mathf.Round(timeInS % 60).ToString() + "s";
|
|
}
|
|
}
|
|
|
|
public void shutdownServer ()
|
|
{
|
|
hasStarted = false;
|
|
network.StopServer();
|
|
|
|
gameObject.SetActive(false);
|
|
next.SetActive(true);
|
|
}
|
|
#endif
|
|
}
|