This commit is contained in:
Andras Schmelczer 2026-09-13 20:53:11 +01:00
commit 36a53f343e
12 changed files with 300431 additions and 0 deletions

View file

@ -0,0 +1,2 @@
# Menu scriptek
Rendkívűl minimális logika, ami a menüben lévő lépkedést vezérli.

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 467a2d65463222d4db9cc222c1dabaed
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Itt lehet állítani, hogy melyik build legyen szerver és melyik kliens.
* WebGL szerver nem lehet.
*/
public class canvasChooser : MonoBehaviour {
public GameObject serverStartCanvas;
public GameObject clientStartCanvas;
public GameObject mainCamera;
// Use this for initialization
void Start () {
#if UNITY_STANDALONE
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
/*serverStartCanvas.SetActive(true);
clientStartCanvas.SetActive(false);
mainCamera.SetActive(false);*/
#endif
#if UNITY_WEBGL
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
#endif
#if UNITY_EDITOR
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
#endif
}
}

View file

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Itt lehet állítani, hogy melyik build legyen szerver és melyik kliens.
* WebGL szerver nem lehet.
*/
public class canvasChooser : MonoBehaviour {
public GameObject serverStartCanvas;
public GameObject clientStartCanvas;
public GameObject mainCamera;
// Use this for initialization
void Start () {
#if UNITY_STANDALONE
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
/*serverStartCanvas.SetActive(true);
clientStartCanvas.SetActive(false);
mainCamera.SetActive(false);*/
#endif
#if UNITY_WEBGL
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
#endif
#if UNITY_EDITOR
serverStartCanvas.SetActive(false);
clientStartCanvas.SetActive(true);
mainCamera.SetActive(true);
#endif
}
}

View file

@ -0,0 +1,170 @@
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
[NetworkSettings(channel = 0, sendInterval = 1)]
public class clientGameMenu : NetworkBehaviour {
public GameObject next;
public NetworkManager network;
private TweetAnimator tweetAnimator;
public TweetContainer tweetContainer;
//Letölti az új tweetet
private void Update ()
{
if(isClient)
{
if (tweetAnimator == null)
tweetAnimator = new TweetAnimator(0.5f, 7.5f, tweetContainer);
tweetAnimator.Animate(Time.deltaTime);
}
}
[ClientRpc(channel = 0)]
public void RpcSetNewTweet (Tweet newTweet)
{
tweetAnimator.SetNewTweet(newTweet);
}
/*public void goBack()
{
network.StopClient();
gameObject.SetActive(false);
next.SetActive(true);
next.GetComponent<clientMenu>().errorField.text = "No errors so far.";
}*/
}
[System.Serializable]
public struct Tweet
{
public TweetAccount account;
public string message;
}
[System.Serializable]
public struct TweetAccount
{
public string realName;
public string name;
public int picID;
}
[System.Serializable]
public struct TweetContainer
{
public GameObject tweetBox;
public Text realName;
public Text message;
public RawImage image;
public List<Texture> pics;
}
//Betölti az új tweetet
public class TweetAnimator
{
private Tweet tweet;
private TweetContainer tweetContainer;
private float elapsedTime;
private float animationTimeout;
private float tweetTimeout;
private bool hasNewTweet = false;
public float opacity = 0.95f;
private enum FadeState
{
notVisible,
fadingIn,
fullyVisible,
fadingOut
}
FadeState fadeState = FadeState.notVisible;
public TweetAnimator (float animationTimeout, float tweetTimeout, TweetContainer tweetContainer)
{
this.animationTimeout = animationTimeout;
this.tweetTimeout = tweetTimeout;
this.tweetContainer = tweetContainer;
}
public void Animate (float deltaTime)
{
elapsedTime += deltaTime;
float q = elapsedTime / animationTimeout;
if (q > 1)
q = 1;
switch (fadeState)
{
case FadeState.notVisible:
tweetContainer.tweetBox.GetComponent<CanvasGroup>().alpha = 0;
if (hasNewTweet)
{
elapsedTime = 0;
changeText();
hasNewTweet = false;
fadeState = FadeState.fadingIn;
}
break;
case FadeState.fadingIn:
tweetContainer.tweetBox.GetComponent<CanvasGroup>().alpha = q * opacity;
if (q >= 1)
{
elapsedTime = 0;
fadeState = FadeState.fullyVisible;
}
break;
case FadeState.fullyVisible:
if (elapsedTime > tweetTimeout)
{
elapsedTime = 0;
fadeState = FadeState.fadingOut;
}
break;
case FadeState.fadingOut:
tweetContainer.tweetBox.GetComponent<CanvasGroup>().alpha = (1 - q) * opacity;
if (q >= 1)
fadeState = FadeState.notVisible;
break;
}
}
public void SetNewTweet(Tweet newTweet)
{
tweet = newTweet;
if (fadeState == FadeState.fadingIn || fadeState == FadeState.fullyVisible)
fadeState = FadeState.fadingOut;
hasNewTweet = true;
}
private void changeText()
{
tweetContainer.realName.text = tweet.account.realName + " <color=blue>@" + tweet.account.name + "</color>";
string formattedMessage = Regex.Replace(tweet.message, "#[a-zA-Z]+", LocalReplaceMatchCase);
tweetContainer.message.text = formattedMessage;
tweetContainer.image.texture = tweetContainer.pics[tweet.account.picID];
}
private string LocalReplaceMatchCase (Match matchExpression)
{
return "<color=blue>" + matchExpression.Value + "</color>";
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c9ca4ea21ecfa14fb07a297a985e20a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
[NetworkSettings(channel = 0, sendInterval = 0)]
public class clientMenu : NetworkBehaviour
{
public TrafficController traffic;
public Text errorField;
public GameObject next;
public bool hasStarted = false;
public NetworkManager network;
public void joinServer (string address)
{
network.networkAddress = address;
network.StartClient();
errorField.text = "Connecting...";
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 83204df2ae6cf744fb64b01124d460c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View 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
}

View file

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
[NetworkSettings(channel = 0, sendInterval = 0)]
public class serverStartMenu : NetworkBehaviour
{
public TrafficController traffic;
public tweetPoller tweet;
public InputField trafficAddress;
public InputField eventAddress;
public GameObject next;
public NetworkManager network;
public void createServer ()
{
if(trafficAddress.text != "")
traffic.url = trafficAddress.text;
if (eventAddress.text != "")
tweet.url = eventAddress.text;
network.StartServer();
gameObject.SetActive(false);
next.SetActive(true);
}
}

View file

@ -0,0 +1,33 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
[NetworkSettings(channel = 0, sendInterval = 0)]
public class serverStartMenu : NetworkBehaviour
{
public TrafficController traffic;
public tweetPoller tweet;
public InputField trafficAddress;
public InputField eventAddress;
public GameObject next;
public NetworkManager network;
public void createServer ()
{
if(trafficAddress.text != "")
traffic.url = trafficAddress.text;
if (eventAddress.text != "")
tweet.url = eventAddress.text;
network.StartServer();
gameObject.SetActive(false);
next.SetActive(true);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 63e28b2f25b615d4aabe4f4fb641e8ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: