Initial
This commit is contained in:
commit
36a53f343e
1 changed files with 300431 additions and 0 deletions
69
UnityProject/Assets/Scripts/menu/serverRunningMenu.cs
Normal file
69
UnityProject/Assets/Scripts/menu/serverRunningMenu.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
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
|
||||
}
|
||||
Loading…
Reference in a new issue