Browse Source

Limit Connected Clients (Tested with 2 phones and laptop, laptop was kicked back to main connection screen)

Limit number can be set in the LoginUIManager.cs script
Josh_Dev_branch
Claire Peta 5 years ago
parent
commit
97e9b8b712
4 changed files with 44 additions and 12 deletions
  1. +2
    -2
      Assets/Scenes/Client Scenes/ClientScene.unity
  2. +2
    -2
      Assets/Scenes/Client Scenes/LoginScreen.unity
  3. +38
    -7
      Assets/Scripts/UI/Client/LoginUIManager.cs
  4. +2
    -1
      Assets/Scripts/animalSelection.cs

+ 2
- 2
Assets/Scenes/Client Scenes/ClientScene.unity View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:824989afec58d87eca7cbb86d0bde0964ff74810bdcb82ef1b018fb45def1c32
size 14609
oid sha256:18d4101b77a4debce58be4d79cde998867da2e07e181f9e819dae5d4830b4545
size 14794

+ 2
- 2
Assets/Scenes/Client Scenes/LoginScreen.unity View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b7d072ed5fffb0afdf3ee9090c2b01468dba1779c7c97d3a8d961897c5b8f1f1
size 259079
oid sha256:d62fbbd19c357e8a8f7dc643cb14fd4912694dcb56997edb1736298346b4bf9a
size 260483

+ 38
- 7
Assets/Scripts/UI/Client/LoginUIManager.cs View File

@ -6,6 +6,9 @@ using TMPro;
public class LoginUIManager : MonoBehaviour
{
public int conn;
public int maxPlayers = 2;
ConnectedClients clients;
[Header("References")]
[SerializeField]
private ClientLoginManager clientManager;
@ -34,6 +37,9 @@ public class LoginUIManager : MonoBehaviour
[SerializeField]
private GameObject WaitObject;
[Header("TooManyPlayerDetails")]
[SerializeField]
private GameObject tooManyObject;
private string serverAddress;
private int serverPort;
@ -44,8 +50,11 @@ public class LoginUIManager : MonoBehaviour
bool animalSelected = false;
bool colorSelected = false;
#region Unity Functions
private void Update()
{
conn = GetComponent<animalSelection>().count;
}
private void OnEnable()
{
clientManager.OnConnectedToServer += OnConnect;
@ -74,10 +83,16 @@ public class LoginUIManager : MonoBehaviour
#region Event Functions
IEnumerator DisplayTooManyCoroutine()
{
tooManyObject.SetActive(true);
yield return new WaitForSeconds(5.0f);
tooManyObject.SetActive(false);
}
public void OnConnect()
{
Title.text = DetailsTitle;
CloseAll();
DetailsObject.SetActive(true);
}
@ -89,10 +104,18 @@ public class LoginUIManager : MonoBehaviour
WaitObject.SetActive(true);
}
public void OnLoginFail()
public void OnLoginFail2Many()
{
Title.text = ConnectionTitle;
CloseAll();
StartCoroutine(DisplayTooManyCoroutine());
ConnectionObject.SetActive(true);
}
public void OnLoginFail()
{
Title.text = ConnectionTitle;
Debug.Log("Failure");
CloseAll();
ConnectionObject.SetActive(true);
}
@ -124,10 +147,18 @@ public class LoginUIManager : MonoBehaviour
public void OnClick_Done()
{
if(colorSelected == true && animalSelected == true && playerName != ""){
clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal);
PlayerPrefs.SetString("LastUsedName", playerName);
}
if(conn <= maxPlayers)
{
if (colorSelected == true && animalSelected == true && playerName != "")
{
clientManager.SendPlayerDetails(playerName, playerColor, playerAnimal);
PlayerPrefs.SetString("LastUsedName", playerName);
}
}
else
{
OnLoginFail2Many();
}
}
public void OnClick_Animal(string playerAnimal)

+ 2
- 1
Assets/Scripts/animalSelection.cs View File

@ -8,6 +8,7 @@ public class animalSelection : MonoBehaviour
{
public ConnectedClients Clients;
public List<Toggle> Animals;
public int count;
//private void OnEnable()
//{
@ -22,7 +23,7 @@ public class animalSelection : MonoBehaviour
public void Update()
{
count = Clients.AllClients.Count;
if (Clients.AllClients.Count > 0)
{
for (int i = 0; i < Clients.AllClients.Count; i++)

Loading…
Cancel
Save