private void SetAllPlayersOnInputModule() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule == null) { return; } inputModule.Clear(); List <int> playersIds = tnGameData.GetPlayersKeysMain(); if (playersIds != null) { for (int index = 0; index < playersIds.Count; ++index) { int playerId = playersIds[index]; if (Hash.IsNullOrEmpty(playerId)) { continue; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData == null) { continue; } string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; PlayerInput playerInput = InputSystem.GetPlayerByNameMain(playerInputName); WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName); if (playerInput != null) { inputModule.AddPlayer(playerInput); } else { if (wifiPlayerInput != null) { inputModule.AddWifiPlayer(wifiPlayerInput); } } } } }
private void SetupInputModule() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule == null) { return; } inputModule.Clear(); tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>(); if (localPartyModule != null) { for (int playerIndex = 0; playerIndex < localPartyModule.playersCount; ++playerIndex) { int playerId = localPartyModule.GetPlayerId(playerIndex); if (Hash.IsNullOrEmpty(playerId)) { continue; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData == null) { continue; } string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; PlayerInput playerInput = InputSystem.GetPlayerByNameMain(playerInputName); WiFiPlayerInput wifiPlyerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName); if (playerInput != null) { inputModule.AddPlayer(playerInput); } else { if (wifiPlyerInput != null) { inputModule.AddWifiPlayer(wifiPlyerInput); } } } } }
private void SetLocalPartyOnInputModule() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule != null) { inputModule.Clear(); tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>(); if (localPartyModule != null) { for (int index = 0; index < localPartyModule.playersCount; ++index) { int playerId = localPartyModule.GetPlayerId(index); if (Hash.IsNullOrEmpty(playerId)) { continue; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData == null) { continue; } string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; if (!StringUtils.IsNullOrEmpty(playerInputName)) { inputModule.AddPlayer(playerInputName); } else { if (!StringUtils.IsNullOrEmpty(wifiPlayerInputName)) { inputModule.AddWifiPlayer(wifiPlayerInputName); } } } } } }
private void ProcessTeam(tnTeamDescription i_TeamDescription) { if (i_TeamDescription == null) { return; } InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule == null) { return; } for (int characterIndex = 0; characterIndex < i_TeamDescription.charactersCount; ++characterIndex) { tnCharacterDescription characterDescription = i_TeamDescription.GetCharacterDescription(characterIndex); if (characterDescription != null) { int playerId = characterDescription.playerId; tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData != null) { string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; if (!StringUtils.IsNullOrEmpty(playerInputName)) { inputModule.AddPlayer(playerInputName); } else { if (!StringUtils.IsNullOrEmpty(wifiPlayerInputName)) { inputModule.AddWifiPlayer(wifiPlayerInputName); } } } } } }
private void SetLocalCaptainOnInputModule() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule != null) { inputModule.Clear(); tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>(); if (localPartyModule != null) { int captainId = localPartyModule.captainId; if (Hash.IsValid(captainId)) { tnPlayerData playerData = tnGameData.GetPlayerDataMain(captainId); if (playerData != null) { string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; if (!StringUtils.IsNullOrEmpty(playerInputName)) { inputModule.AddPlayer(playerInputName); } else { if (!StringUtils.IsNullOrEmpty(wifiPlayerInputName)) { inputModule.AddWifiPlayer(wifiPlayerInputName); } } } } } } }
private void SetupInputModule() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule == null) { return; } inputModule.Clear(); tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>(); if (teamsModule != null) { for (int teamIndex = 0; teamIndex < teamsModule.teamsCount; ++teamIndex) { tnTeamDescription teamDescription = teamsModule.GetTeamDescription(teamIndex); if (teamDescription == null) { continue; } for (int characterIndex = 0; characterIndex < teamDescription.charactersCount; ++characterIndex) { tnCharacterDescription characterDescription = teamDescription.GetCharacterDescription(characterIndex); if (characterDescription == null) { continue; } int playerId = characterDescription.playerId; if (Hash.IsNullOrEmpty(playerId)) { continue; } tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId); if (playerData == null) { continue; } string playerInputName = playerData.playerInputName; string wifiPlayerInputName = playerData.wifiPlayerInputName; PlayerInput playerInput = InputSystem.GetPlayerByNameMain(playerInputName); WiFiPlayerInput wifiPlyerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName); if (playerInput != null) { inputModule.AddPlayer(playerInput); } else { if (wifiPlyerInput != null) { inputModule.AddWifiPlayer(wifiPlyerInput); } } } } } }
public override void OnEnter() { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule != null) { // Clear input module. inputModule.Clear(); // Handle players. if (useAllPlayers != null && useAllPlayers.Value) { for (int playerIndex = 0; playerIndex < InputSystem.numPlayersMain; ++playerIndex) { PlayerInput playerInput = InputSystem.GetPlayerByIndexMain(playerIndex); inputModule.AddPlayer(playerInput); } } else { if (players != null) { for (int playerIndex = 0; playerIndex < players.Length; ++playerIndex) { FsmString str = players[playerIndex]; if (!str.IsNone && str.Value != "") { inputModule.AddPlayer(str.Value); } } } } // Handle wifi players. if (useAllWifiPlayers != null && useAllWifiPlayers.Value) { for (int playerIndex = 0; playerIndex < WiFiInputSystem.playersCountMain; ++playerIndex) { WiFiPlayerInput playerInput = WiFiInputSystem.GetPlayerByIndexMain(playerIndex); inputModule.AddWifiPlayer(playerInput); } } else { if (wifiPlayers != null) { for (int playerIndex = 0; playerIndex < wifiPlayers.Length; ++playerIndex) { FsmString str = wifiPlayers[playerIndex]; if (!str.IsNone && str.Value != "") { inputModule.AddWifiPlayer(str.Value); } } } } } Finish(); }
protected override void OnUpdate(float i_DeltaTime) { base.OnUpdate(i_DeltaTime); if (viewInstance == null || !viewInstance.isOpen) { return; } // Clear change flags. for (int index = 0; index < m_ChangeFlags.Length; ++index) { m_ChangeFlags[index] = false; } int freeSlot = GetFreeSlotCount(); // Listen for new join. if (m_ReceiveInput) { if (freeSlot > 0) { List <int> playersIds = tnGameData.GetPlayersKeysMain(); if (playersIds != null) { for (int index = 0; index < playersIds.Count; ++index) { int playerId = playersIds[index]; if (IsAlreadyJoined(playerId)) { continue; } bool startPressed = tnInputUtils.GetButtonDown(playerId, "Start"); if (startPressed) { int targetIndex = GetFirstFreeSlotIndex(); if (targetIndex >= 0) { m_JoinedPlayerIds[targetIndex] = playerId; m_ChangeFlags[targetIndex] = true; --freeSlot; } } } } } // Check if someone leave the group. for (int index = 0; index < m_JoinedPlayerIds.Length; ++index) { int playerId = m_JoinedPlayerIds[index]; if (Hash.IsNullOrEmpty(playerId)) { continue; } bool cancelPressed = tnInputUtils.GetButtonDown(playerId, "Cancel"); if (cancelPressed) { m_JoinedPlayerIds[index] = Hash.s_NULL; m_ChangeFlags[index] = true; ++freeSlot; } } } // Cache if something has changed. bool somethingChanged = false; for (int index = 0; index < m_ChangeFlags.Length; ++index) { somethingChanged |= m_ChangeFlags[index]; } // Set players on input module. if (somethingChanged) { if (IsAllFree()) { SetAllPlayersOnInputModule(); } else { InputModule inputModule = UIEventSystem.inputModuleMain; if (inputModule != null) { inputModule.Clear(); for (int index = 0; index < m_JoinedPlayerIds.Length; ++index) { int playerId = m_JoinedPlayerIds[index]; if (Hash.IsNullOrEmpty(playerId)) { continue; } PlayerInput playerInput; WiFiPlayerInput wifiPlayerInput; tnInputUtils.GetPlayersInputs(playerId, out playerInput, out wifiPlayerInput); if (playerInput != null) { inputModule.AddPlayer(playerInput); } else { if (wifiPlayerInput != null) { inputModule.AddWifiPlayer(wifiPlayerInput); } } } } } } // Update view. if (somethingChanged) { // Update slots. int joinedIndex = 0; string photonPlayerName = PhotonNetwork.playerName; for (int index = 0; index < m_JoinedPlayerIds.Length; ++index) { bool changed = m_ChangeFlags[index]; int playerId = m_JoinedPlayerIds[index]; bool isFree = Hash.IsNullOrEmpty(playerId); if (!isFree) { SetPlayerName(index, photonPlayerName, joinedIndex); ++joinedIndex; } if (!changed) { continue; } if (isFree) { // Free slot. FreePlayerSlot(index); } else { // Set slot. SetPlayerSlot(index, playerId); } } // Update triggers. if (IsAllFree()) { viewInstance.SetProceedTriggerCanSend(false); viewInstance.SetCancelTriggerActive(false); viewInstance.SetCancelTriggerCanSend(false); viewInstance.SetBackTriggerActive(true); viewInstance.SetBackTriggerCanSend(true); } else { viewInstance.SetProceedTriggerCanSend(true); viewInstance.SetCancelTriggerActive(true); viewInstance.SetCancelTriggerCanSend(true); viewInstance.SetBackTriggerActive(false); viewInstance.SetBackTriggerCanSend(false); } } }
public void Initialize() { GameObject root = new GameObject("Root"); root.transform.SetParent(transform); EventSystem eventSystem = root.AddComponent <EventSystem>(); eventSystem.firstSelectedGameObject = null; eventSystem.sendNavigationEvents = true; eventSystem.pixelDragThreshold = 5; m_EventSystem = eventSystem; /* * * StandaloneInputModule inputModule = uiEventSystem.AddComponent<StandaloneInputModule>(); * inputModule.horizontalAxis = "Horizontal"; * inputModule.verticalAxis = "Vertical"; * inputModule.submitButton = "Submit"; * inputModule.cancelButton = "Cancel"; * inputModule.inputActionsPerSecond = 10f; * inputModule.repeatDelay = 0.5f; * inputModule.forceModuleActive = false; * */ InputModule inputModule = root.AddComponent <InputModule>(); InputModuleConfig inputModuleConfig = Resources.Load <InputModuleConfig>("Input/InputModuleConfig"); if (inputModuleConfig != null) { inputModule.horizontalAxis = inputModuleConfig.horizontalAxis; inputModule.verticalAxis = inputModuleConfig.verticalAxis; inputModule.submitButton = inputModuleConfig.submitButton; inputModule.cancelButton = inputModuleConfig.cancelButton; inputModule.wifiHorizontalAxis = inputModuleConfig.wifiHorizontalAxis; inputModule.wifiVerticalAxis = inputModuleConfig.wifiVerticalAxis; inputModule.wifiSubmitButton = inputModuleConfig.wifiSubmitButton; inputModule.wifiCancelButton = inputModuleConfig.wifiCancelButton; inputModule.inputActionsPerSecond = inputModuleConfig.inputActionsPerSecond; inputModule.moveOneElementPerAxisPress = inputModuleConfig.moveOneElementPerAxisPress; inputModule.repeatDelay = inputModuleConfig.repeatDelay; inputModule.axisDeadzone = inputModuleConfig.axisDeadzone; inputModule.allowMouseInput = inputModuleConfig.allowMouseInput; inputModule.allowMouseInputIfTouchSupported = inputModuleConfig.allowMouseInputIfTouchSupported; inputModule.allowActivationOnMobileDevice = inputModule.allowActivationOnMobileDevice; for (int index = 0; index < inputModuleConfig.defaultPlayersCount; ++index) { string player = inputModuleConfig.GetPlayer(index); if (StringUtils.IsNullOrEmpty(player)) { continue; } inputModule.AddPlayer(player); } for (int index = 0; index < inputModuleConfig.defaultWifiPlayersCount; ++index) { string player = inputModuleConfig.GetWifiPlayer(index); if (StringUtils.IsNullOrEmpty(player)) { continue; } inputModule.AddWifiPlayer(player); } } else { inputModule.horizontalAxis = "Horizontal"; inputModule.verticalAxis = "Vertical"; inputModule.submitButton = "Submit"; inputModule.cancelButton = "Cancel"; inputModule.inputActionsPerSecond = 4f; inputModule.moveOneElementPerAxisPress = true; inputModule.repeatDelay = 0f; inputModule.axisDeadzone = 0f; } m_InputModule = inputModule; // TODO : Configure PlayerInput designed to handle UI input. }