68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.Events;
|
|
|
|
public class GameRoomButton : MonoBehaviour
|
|
{
|
|
private Button thisButton;
|
|
[SerializeField] private TextMeshProUGUI playerCountText;
|
|
public TextMeshProUGUI buttonNameText;
|
|
[SerializeField] private GameObject lockIcon;
|
|
|
|
private void Awake()
|
|
{
|
|
lockIcon.SetActive(false);
|
|
thisButton = GetComponent<Button>();
|
|
}
|
|
|
|
|
|
public void AssignButtonInfo(string ownerName, int playersInRoom, int maxPlayersAllowed)
|
|
{
|
|
buttonNameText.text = $"{ownerName}'s Room";
|
|
playerCountText.text = $"{playersInRoom}/{maxPlayersAllowed}";
|
|
gameObject.name = $"Join_Room_{ownerName}";
|
|
|
|
thisButton.onClick.AddListener(new UnityAction(() => ActionButton.ButtonPressed(gameObject.name)));
|
|
|
|
SetButtonNavigation(maxPlayersAllowed);
|
|
}
|
|
|
|
private void SetButtonNavigation(int maxPlayers)
|
|
{
|
|
Navigation buttonNav = thisButton.navigation;
|
|
buttonNav.mode = Navigation.Mode.Explicit;
|
|
|
|
//Up Down Navigation
|
|
int thisChildIndex = transform.GetSiblingIndex();
|
|
|
|
Button previousButton = transform.parent.GetChild(thisChildIndex - 1).GetComponent<Button>();
|
|
Navigation previousButtonNav = previousButton.navigation;
|
|
previousButtonNav.selectOnDown = thisButton;
|
|
previousButton.navigation = previousButtonNav;
|
|
|
|
buttonNav.selectOnUp = previousButton;
|
|
|
|
//Left Right Navigation
|
|
if(maxPlayers == 2)
|
|
{
|
|
buttonNav.selectOnLeft = UIManager.Instance.SoloInstanceParent.GetChild(0).GetComponent<Selectable>();
|
|
buttonNav.selectOnRight = UIManager.Instance.SquadInstanceParent.GetChild(0).GetComponent<Selectable>();
|
|
}
|
|
else if(maxPlayers == 4)
|
|
{
|
|
buttonNav.selectOnLeft = UIManager.Instance.DuoInstanceParent.GetChild(0).GetComponent<Selectable>();
|
|
buttonNav.selectOnRight = null;
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"{maxPlayers} amount is incorrect. There should be only 2 or 4.");
|
|
}
|
|
|
|
thisButton.navigation = buttonNav;
|
|
}
|
|
|
|
}
|