private void SpawnGamepads() { if (m_UIGamepadPrefab == null) { return; } if (m_ControllersGrid == null) { return; } if (m_ControllersRoot == null) { return; } List <int> playersKeys = tnGameData.GetPlayersKeysMain(); if (playersKeys == null) { return; } int playersCount = InputSystem.numPlayersMain; int max = Mathf.Min(playersCount, playersKeys.Count); for (int index = 0; index < max; ++index) { ControllerAnchor anchor = m_ControllersGrid.GetAnchorByIndex(index); if (anchor != null) { int playerId = playersKeys[index]; tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData != null) { tnUIGamepad gamepad = GameObject.Instantiate <tnUIGamepad>(m_UIGamepadPrefab); gamepad.transform.SetParent(m_ControllersRoot, false); gamepad.SetPlayerId(playerId); gamepad.SetPlayerName(playerData.playerInputName); gamepad.SetDefaultAnchor(anchor); gamepad.gameObject.name = playerData.name + "_Pad"; Color color = playerData.color; gamepad.SetColor(color, true); gamepad.SetTeamsManagers(m_TeamA, m_TeamB); gamepad.hasFocus = false; m_Gamepads.Add(gamepad); } } } }
private void CheckProceed() { if (m_Gamepads == null || m_Phones == null || m_TriggerProceed == null) { return; } bool confirm = false; // Check gamepads for (int gamepadIndex = 0; gamepadIndex < m_Gamepads.Count; ++gamepadIndex) { tnUIGamepad gamepad = m_Gamepads[gamepadIndex]; if (gamepad != null) { if (gamepad.deviceState == DeviceState.Left || gamepad.deviceState == DeviceState.Right) { confirm |= gamepad.GetProceedButton(); } } } // Check phones for (int phoneIndex = 0; phoneIndex < m_Phones.Count; ++phoneIndex) { tnUIPhone phone = m_Phones[phoneIndex]; if (phone != null) { if (phone.deviceState == DeviceState.Left || phone.deviceState == DeviceState.Right) { confirm |= phone.GetProceedButton(); } } } if (confirm) { m_TriggerProceed.Invoke(); } }
private void CheckCancel() { if (m_Gamepads == null || m_Phones == null || m_TriggerCancel == null) { return; } bool cancel = false; // Check gamepads for (int gamepadIndex = 0; gamepadIndex < m_Gamepads.Count; ++gamepadIndex) { tnUIGamepad gamepad = m_Gamepads[gamepadIndex]; if (gamepad != null) { cancel |= gamepad.GetCancelButton(); } } // Check phones for (int phoneIndex = 0; phoneIndex < m_Phones.Count; ++phoneIndex) { tnUIPhone phone = m_Phones[phoneIndex]; if (phone != null) { cancel |= phone.GetCancelButton(); } } if (cancel) { m_TriggerCancel.Invoke(); } }
public override void OnExit() { m_HasFocus = false; for (int phoneIndex = 0; phoneIndex < m_Phones.Count; ++phoneIndex) { tnUIPhone phone = m_Phones[phoneIndex]; if (phone != null) { phone.hasFocus = false; } } for (int gamepadIndex = 0; gamepadIndex < m_Gamepads.Count; ++gamepadIndex) { tnUIGamepad gamepad = m_Gamepads[gamepadIndex]; if (gamepad != null) { gamepad.hasFocus = false; } } base.OnExit(); }