Add party to lobby menu
This commit is contained in:
9
Assets/Scripts/Data/PlayerInfo.cs
Normal file
9
Assets/Scripts/Data/PlayerInfo.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public struct PlayerInfo
|
||||
{
|
||||
public string Name;
|
||||
public Sprite Image;
|
||||
}
|
||||
11
Assets/Scripts/Data/PlayerInfo.cs.meta
Normal file
11
Assets/Scripts/Data/PlayerInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f2fb7ea93e56444496e2715f01f7336
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -62,6 +62,19 @@ public class GameManager : NetworkBehaviour
|
||||
networkManager.StartHost();
|
||||
}
|
||||
|
||||
public void LeaveGame()
|
||||
{
|
||||
networkManager.Shutdown(true);
|
||||
//if (networkManager.IsHost)
|
||||
//{
|
||||
// networkManager.Shutdown(true);
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// networkManager.
|
||||
//}
|
||||
}
|
||||
|
||||
private void OnClientStarted()
|
||||
{
|
||||
OnConnected?.Invoke();
|
||||
|
||||
@@ -39,6 +39,16 @@ public class LobbyMenuUI : MonoBehaviour
|
||||
[SerializeField]
|
||||
private Button hostButton;
|
||||
|
||||
[Title("Connected")]
|
||||
[SerializeField]
|
||||
private GameObject connected;
|
||||
|
||||
[SerializeField]
|
||||
private PlayerItemUI[] playerItems;
|
||||
|
||||
[SerializeField]
|
||||
private Button leaveButton;
|
||||
|
||||
private bool isConnected => gameManager.IsMultiplayer;
|
||||
|
||||
private void Start()
|
||||
@@ -50,6 +60,7 @@ public class LobbyMenuUI : MonoBehaviour
|
||||
|
||||
joinButton.onClick.AddListener(() => JoinClicked());
|
||||
hostButton.onClick.AddListener(() => HostClicked());
|
||||
leaveButton.onClick.AddListener(() => LeaveClicked());
|
||||
gameManager.OnConnected.AddListener(() => UpdateUI());
|
||||
gameManager.OnDisconnected.AddListener(() => UpdateUI());
|
||||
|
||||
@@ -59,9 +70,9 @@ public class LobbyMenuUI : MonoBehaviour
|
||||
private void UpdateUI()
|
||||
{
|
||||
joinOrHost.SetActive(!isConnected);
|
||||
connected.SetActive(isConnected);
|
||||
joinButton.interactable = true;
|
||||
hostButton.interactable = true;
|
||||
Debug.Log(isConnected);
|
||||
}
|
||||
|
||||
private void JoinClicked()
|
||||
@@ -76,6 +87,10 @@ public class LobbyMenuUI : MonoBehaviour
|
||||
gameManager.HostGame();
|
||||
joinButton.interactable = false;
|
||||
hostButton.interactable = false;
|
||||
}
|
||||
|
||||
private void LeaveClicked()
|
||||
{
|
||||
gameManager.LeaveGame();
|
||||
}
|
||||
}
|
||||
|
||||
50
Assets/Scripts/UI/PlayerItemUI.cs
Normal file
50
Assets/Scripts/UI/PlayerItemUI.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Sirenix.OdinInspector;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PlayerItemUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI nameText;
|
||||
|
||||
[SerializeField]
|
||||
private Image playerImage;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject emptyGroup;
|
||||
|
||||
[SerializeField]
|
||||
private GameObject activeGroup;
|
||||
|
||||
[ReadOnly]
|
||||
[SerializeField]
|
||||
private PlayerInfo? playerInfo;
|
||||
|
||||
bool isEmpty => playerInfo == null;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void Setup(PlayerInfo? playerInfo)
|
||||
{
|
||||
this.playerInfo = playerInfo;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void UpdateUI()
|
||||
{
|
||||
emptyGroup.SetActive(isEmpty);
|
||||
activeGroup.SetActive(!isEmpty);
|
||||
|
||||
if (!isEmpty)
|
||||
{
|
||||
nameText.text = playerInfo?.Name;
|
||||
playerImage.sprite = playerInfo?.Image;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/UI/PlayerItemUI.cs.meta
Normal file
11
Assets/Scripts/UI/PlayerItemUI.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d0332147f497ef43b76bf6555e0421e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user