118 lines
3.5 KiB
C#
118 lines
3.5 KiB
C#
using UnityEngine;
|
|
using GeoSus.Client;
|
|
using Subsystems;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System;
|
|
using TMPro;
|
|
/*
|
|
GameManager - hlavní tøida pro správu hry
|
|
GameManager_Network - subsystém pro správu komunikace se serverem
|
|
GameManager_Game - subsystém pro správu logiky hry (sabotáže, tasky, atd.)
|
|
GameManager_Map - subsystém pro správu mapy a prostøedí
|
|
GameManager_Input - subsystém pro správu vstupu od hráèe
|
|
GameManager_UI - subsystém pro správu uživatelského rozhraní
|
|
GamaManager_Stats - subsystém pro správu statistik pro server
|
|
*/
|
|
public class GameManager : MonoBehaviour
|
|
{
|
|
[Header("Subsystems")]
|
|
protected GameManager_Network networkSubsystem;
|
|
protected GameManager_UI uiSubsystem;
|
|
protected GameManager_Map mapSubsystem;
|
|
|
|
protected GameClient gameClient;
|
|
|
|
[Header("Player Info")]
|
|
public string displayName;
|
|
|
|
[Header("UI Elements")]
|
|
public Canvas JoinCreateLobby;
|
|
public Canvas InLobby;
|
|
public Canvas LoadingScreen;
|
|
public Canvas GameScreen;
|
|
|
|
|
|
[Header("Map")]
|
|
public GameObject MapCenterPoint;
|
|
public BuildingSettings buildingSettings;
|
|
public PathwaySettings pathwaySettings;
|
|
public AreaSettings areaSettings;
|
|
|
|
|
|
void Start()
|
|
{
|
|
DontDestroyOnLoad(this);
|
|
if (displayName == null || displayName == "")
|
|
{
|
|
displayName = "Player_" + UnityEngine.Random.Range(1000, 9999).ToString();
|
|
}
|
|
gameClient = new GameClient(GenerateUUID(), /*displayName*/ GenerateUsername());
|
|
uiSubsystem = new GameManager_UI(gameClient, JoinCreateLobby, InLobby, LoadingScreen, GameScreen);
|
|
networkSubsystem = new GameManager_Network(gameClient);
|
|
mapSubsystem = new GameManager_Map(gameClient, MapCenterPoint, buildingSettings, pathwaySettings, areaSettings);
|
|
networkSubsystem.OpenConection();
|
|
}
|
|
private void Update()
|
|
{
|
|
if (gameClient.CurrentLobbyState != null)
|
|
{
|
|
uiSubsystem.UpdateLobbyUI();
|
|
}
|
|
try
|
|
{
|
|
if (gameClient.CurrentLobbyState.MapDataReady)
|
|
{
|
|
mapSubsystem.BuildMap();
|
|
gameClient.CurrentLobbyState.MapDataReady = false;
|
|
}
|
|
}
|
|
catch (NullReferenceException ex) { }
|
|
|
|
}
|
|
|
|
|
|
protected string GenerateUUID()
|
|
{
|
|
string UUID = System.Guid.NewGuid().ToString();
|
|
Debug.Log(UUID);
|
|
return UUID;
|
|
}
|
|
protected string GenerateUsername()
|
|
{
|
|
string Username = UnityEngine.Random.Range(0,10).ToString() + UnityEngine.Random.Range(0, 10).ToString() + UnityEngine.Random.Range(0, 10).ToString() + UnityEngine.Random.Range(0, 10).ToString();
|
|
Debug.Log(Username);
|
|
return Username;
|
|
}
|
|
public void CreateLobbyButton()
|
|
{
|
|
networkSubsystem.CrateLobby(50.7727264, 15.0719876);
|
|
}
|
|
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();
|
|
}
|
|
public void StartGameButton()
|
|
{
|
|
networkSubsystem.StartGame();
|
|
}
|
|
void OnApplicationQuit()
|
|
{
|
|
gameClient.Disconnect();
|
|
}
|
|
}
|