Files

97 lines
3.2 KiB
C#
Raw Permalink Normal View History

2021-08-25 16:15:09 +02:00
using UnityEngine;
2023-10-04 15:28:25 +03:00
using UnityEngine.EventSystems;
2021-08-25 16:15:09 +02:00
using UnityEngine.InputSystem;
2023-10-04 15:28:25 +03:00
using UnityEngine.UI;
2021-08-25 16:15:09 +02:00
public class PlayersMenu : BaseMenu
{
2023-10-03 02:33:28 +03:00
[SerializeField] private HomeMenu _homeMenu = default;
2022-12-14 18:33:44 +02:00
[SerializeField] private CharacterMenu _characterMenu = default;
2023-09-22 16:54:55 +03:00
[SerializeField] private PlayerIcon[] _playerIcons = default;
2023-09-10 12:07:02 +03:00
[SerializeField] private RectTransform[] _playerGroups = default;
2022-12-14 18:33:44 +02:00
[SerializeField] private GameObject _cpuTextRight = default;
[SerializeField] private GameObject _cpuTextLeft = default;
2023-08-28 22:50:54 +03:00
[SerializeField] private PromptsInput _prompts = default;
2023-10-04 15:28:25 +03:00
[SerializeField] private Selectable _firstSelectable = default;
2022-12-14 18:33:44 +02:00
private Audio _audio;
public GameObject CpuTextRight { get { return _cpuTextRight; } private set { } }
public GameObject CpuTextLeft { get { return _cpuTextLeft; } private set { } }
2023-09-10 12:07:02 +03:00
public RectTransform[] PlayerGroups { get { return _playerGroups; } set { } }
2021-08-25 16:15:09 +02:00
2022-12-14 18:33:44 +02:00
void Awake()
{
_audio = GetComponent<Audio>();
}
2021-09-19 20:50:43 +02:00
2022-12-14 18:33:44 +02:00
private void UpdateVisiblePlayers(InputDevice inputDevice, InputDeviceChange inputDeviceChange)
{
for (int i = 0; i < _playerIcons.Length; i++)
2023-09-22 16:54:55 +03:00
_playerIcons[i].SetController();
2022-12-14 18:33:44 +02:00
}
2021-08-26 22:36:18 +02:00
2022-12-14 18:33:44 +02:00
public void OpenOtherMenu()
{
2023-09-22 16:54:55 +03:00
_audio.Sound("Pressed").Play();
if (PlayerGroups[0].childCount == 0 && PlayerGroups[2].childCount == 0)
_playerIcons[0].ConfirmQuickAssign();
else if (gameObject.activeInHierarchy)
2022-12-14 18:33:44 +02:00
{
gameObject.SetActive(false);
2023-10-03 02:33:28 +03:00
Hide();
2023-10-03 11:33:37 +03:00
_homeMenu.Hide();
2022-12-14 18:33:44 +02:00
_characterMenu.Show();
}
}
2021-09-05 00:46:11 +02:00
2023-10-01 13:19:40 +03:00
public void OpenNextMenu(int intToCheck)
{
if (PlayerGroups[intToCheck].childCount == 0)
return;
if (gameObject.activeInHierarchy)
{
gameObject.SetActive(false);
2023-10-03 02:33:28 +03:00
Hide();
2023-10-03 11:33:37 +03:00
_homeMenu.Hide();
2023-10-01 13:19:40 +03:00
_characterMenu.Show();
}
}
2022-12-14 18:33:44 +02:00
public void OpenKeyboardCoOp()
{
_audio.Sound("Pressed").Play();
2023-09-22 16:54:55 +03:00
SceneSettings.ControllerOne = _playerIcons[0].PlayerInput.devices[0];
SceneSettings.ControllerTwo = _playerIcons[0].PlayerInput.devices[0];
2022-12-14 18:33:44 +02:00
gameObject.SetActive(false);
2023-10-03 02:33:28 +03:00
Hide();
2023-10-03 11:33:37 +03:00
_homeMenu.Hide();
2022-12-14 18:33:44 +02:00
_characterMenu.Show();
}
2021-09-08 00:25:37 +02:00
2023-09-22 16:54:55 +03:00
public void CheckCPU()
{
_cpuTextLeft.gameObject.SetActive(_playerGroups[0].childCount == 0 ? true : false);
_cpuTextRight.gameObject.SetActive(_playerGroups[2].childCount == 0 ? true : false);
}
2022-12-14 18:33:44 +02:00
void OnDisable()
{
2023-10-04 15:28:25 +03:00
_firstSelectable.Select();
2023-09-22 16:54:55 +03:00
if (_playerGroups[0].childCount > 0)
SceneSettings.ControllerOne = _playerGroups[0].GetChild(0).GetComponent<PlayerIcon>().PlayerInput.devices[0];
if (_playerGroups[2].childCount > 0)
SceneSettings.ControllerTwo = _playerGroups[2].GetChild(0).GetComponent<PlayerIcon>().PlayerInput.devices[0];
2022-12-14 18:33:44 +02:00
_cpuTextLeft.SetActive(true);
_cpuTextRight.SetActive(true);
InputSystem.onDeviceChange -= UpdateVisiblePlayers;
}
2022-03-12 18:06:55 +01:00
2022-12-14 18:33:44 +02:00
private void OnEnable()
{
2023-10-04 15:28:25 +03:00
EventSystem.current.SetSelectedGameObject(null);
2023-08-28 22:50:54 +03:00
_prompts.gameObject.SetActive(true);
2022-12-14 18:33:44 +02:00
InputSystem.onDeviceChange += UpdateVisiblePlayers;
UpdateVisiblePlayers(null, default);
}
2021-08-25 16:15:09 +02:00
}