Added Lobbies
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
/*
|
||||
GameManager - hlavní tøida pro správu hry
|
||||
GameManager_Network - subsystém pro správu komunikace se serverem
|
||||
@@ -16,10 +17,19 @@ using System.Collections.Generic;
|
||||
*/
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
protected GameClient gameClient;
|
||||
[Header("Subsystems")]
|
||||
protected GameManager_Network networkSubsystem;
|
||||
protected GameManager_UI uiSubsystem;
|
||||
|
||||
|
||||
protected GameClient gameClient;
|
||||
[Header("Player Info")]
|
||||
public string displayName;
|
||||
|
||||
|
||||
[Header("UI Elements")]
|
||||
public Canvas JoinCreateLobby;
|
||||
public Canvas InLobby;
|
||||
|
||||
void Start()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
@@ -27,11 +37,20 @@ public class GameManager : MonoBehaviour
|
||||
{
|
||||
displayName = "Player_" + Random.Range(1000, 9999).ToString();
|
||||
}
|
||||
gameClient = new GameClient(GenerateUUID(), displayName);
|
||||
gameClient = new GameClient(GenerateUUID(), /*displayName*/ GenerateUsername());
|
||||
uiSubsystem = new GameManager_UI(gameClient, JoinCreateLobby, InLobby);
|
||||
networkSubsystem = new GameManager_Network(gameClient);
|
||||
networkSubsystem.checkState();
|
||||
networkSubsystem.OpenConection();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (gameClient.CurrentLobbyState != null)
|
||||
{
|
||||
uiSubsystem.UpdateLobbyUI();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected string GenerateUUID()
|
||||
{
|
||||
@@ -39,4 +58,34 @@ public class GameManager : MonoBehaviour
|
||||
Debug.Log(UUID);
|
||||
return UUID;
|
||||
}
|
||||
protected string GenerateUsername()
|
||||
{
|
||||
string Username = Random.Range(0,10).ToString() + Random.Range(0, 10).ToString() + Random.Range(0, 10).ToString() + Random.Range(0, 10).ToString();
|
||||
Debug.Log(Username);
|
||||
return Username;
|
||||
}
|
||||
public void CreateLobbyButton()
|
||||
{
|
||||
networkSubsystem.CrateLobby(50.0755, 14.4378);
|
||||
}
|
||||
public void JoinLobbyButton()
|
||||
{
|
||||
TMP_InputField joinCode = JoinCreateLobby.transform.Find("InputCode").GetComponent<TMP_InputField>();
|
||||
if (joinCode.text != null && joinCode.text != "")
|
||||
{
|
||||
networkSubsystem.JoinLobby(joinCode.text);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Join code is empty!");
|
||||
}
|
||||
}
|
||||
public void LeaveLobbyButton()
|
||||
{
|
||||
networkSubsystem.LeaveLobby();
|
||||
}
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
gameClient.Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user