// MonoBehaviour's interface

        void Awake()
        {
            // Get players references.

            {
                for (int playerIndex = 0; playerIndex < m_PlayerNames.Count; ++playerIndex)
                {
                    string      playerName  = m_PlayerNames[playerIndex];
                    PlayerInput playerInput = InputSystem.GetPlayerByNameMain(playerName);
                    if (playerInput != null)
                    {
                        m_Players.Add(playerInput);
                    }
                }
            }

            if (m_UseWifi)
            {
                // Get wifi players references.

                for (int playerIndex = 0; playerIndex < m_WifiPlayerNames.Count; ++playerIndex)
                {
                    string          playerName  = m_WifiPlayerNames[playerIndex];
                    WiFiPlayerInput playerInput = WiFiInputSystem.GetPlayerByNameMain(playerName);
                    if (playerInput != null)
                    {
                        m_WifiPlayers.Add(playerInput);
                    }
                }
            }
        }
Exemple #2
0
    private void CheckForPreviousControl(int i_PlayerIndex)
    {
        if (!IsValidIndex(i_PlayerIndex))
        {
            return;
        }

        bool cancelPressed = false;

        PlayerInput playerInput = m_Players[i_PlayerIndex];

        if (playerInput != null)
        {
            cancelPressed = playerInput.GetButtonDown(s_PlayerInput_Cancel);
        }
        else
        {
            WiFiPlayerInput wifiPlayerInput = m_WifiPlayers[i_PlayerIndex];
            if (wifiPlayerInput != null)
            {
                cancelPressed = wifiPlayerInput.GetButtonDown(s_WiFiPlayerInput_Cancel);
            }
        }

        if (cancelPressed)
        {
            PopControllingMap(i_PlayerIndex);
        }
    }
    // CTOR

    public tnWiFiPlayerInputFiller(WiFiPlayerInput i_PlayerInput)
    {
        m_PlayerInput = i_PlayerInput;

        m_HorizontalFilter = new FilteredFloat(0.01f, 0.01f);
        m_VerticalFilter   = new FilteredFloat(0.01f, 0.01f);
    }
    // CTOR

    public WiFiPlayer(string i_PlayerName, WiFiPlayerInput i_PlayerInput)
    {
        m_PlayerName  = i_PlayerName;
        m_PlayerInput = i_PlayerInput;
        m_Buttons     = new List <string>();
        m_Axes        = new List <string>();
    }
        // INTERNALS

        private void RefreshPlayers()
        {
            m_Players.Clear();
            m_WifiPlayers.Clear();

            InputModule inputModule = UIEventSystem.inputModuleMain;

            if (inputModule == null)
            {
                return;
            }

            for (int playerIndex = 0; playerIndex < inputModule.playersCount; ++playerIndex)
            {
                PlayerInput playerInput = inputModule.GetPlayerInput(playerIndex);
                m_Players.Add(playerInput);
            }

            if (m_UseWifi)
            {
                for (int playerIndex = 0; playerIndex < inputModule.wifiPlayersCount; ++playerIndex)
                {
                    WiFiPlayerInput playerInput = inputModule.GetWifiPlayerInput(playerIndex);
                    m_WifiPlayers.Add(playerInput);
                }
            }
        }
Exemple #6
0
    public static bool GetPlayersInputs(int i_PlayerId, out PlayerInput o_PlayerInput, out WiFiPlayerInput o_WifiPlayerInput)
    {
        o_PlayerInput     = null;
        o_WifiPlayerInput = null;

        if (Hash.IsNullOrEmpty(i_PlayerId))
        {
            return(false);
        }

        tnPlayerData playerData = tnGameData.GetPlayerDataMain(i_PlayerId);

        if (playerData == null)
        {
            return(false);
        }

        string playerInputName     = playerData.playerInputName;
        string wifiPlayerInputName = playerData.wifiPlayerInputName;

        PlayerInput     playerInput     = InputSystem.GetPlayerByNameMain(playerInputName);
        WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName);

        o_PlayerInput     = playerInput;
        o_WifiPlayerInput = wifiPlayerInput;

        return(true);
    }
Exemple #7
0
    private MoveDir GetMoveDirection(WiFiPlayerInput i_PlayerInput)
    {
        if (i_PlayerInput == null)
        {
            return(MoveDir.None);
        }
        else if (i_PlayerInput.GetNegativeButtonDown(s_WiFiPlayerInput_Horizontal))
        {
            return(MoveDir.Left);
        }
        else if (i_PlayerInput.GetPositiveButtonDown(s_WiFiPlayerInput_Horizontal))
        {
            return(MoveDir.Right);
        }
        else if (i_PlayerInput.GetPositiveButtonDown(s_WiFiPlayerInput_Vertical))
        {
            return(MoveDir.Up);
        }
        else if (i_PlayerInput.GetNegativeButtonDown(s_WiFiPlayerInput_Vertical))
        {
            return(MoveDir.Down);
        }

        return(MoveDir.None); // Something went wrong.
    }
Exemple #8
0
    private void CheckForCancelation(int i_PlayerIndex)
    {
        if (!IsValidIndex(i_PlayerIndex))
        {
            return;
        }

        IndexList controlledPlayers = m_ControllingMap[i_PlayerIndex];

        int controlledPlayerIndex = controlledPlayers.GetLast();

        if (!IsValidIndex(controlledPlayerIndex))
        {
            return;
        }

        bool cancelPressed = false;

        PlayerInput playerInput = m_Players[i_PlayerIndex];

        if (playerInput != null)
        {
            cancelPressed = playerInput.GetButtonDown(s_PlayerInput_Cancel);
        }
        else
        {
            WiFiPlayerInput wifiPlayerInput = m_WifiPlayers[i_PlayerIndex];
            if (wifiPlayerInput != null)
            {
                cancelPressed = wifiPlayerInput.GetButtonDown(s_WiFiPlayerInput_Cancel);
            }
        }

        if (cancelPressed)
        {
            GameObject currentSelection = m_Selections[controlledPlayerIndex];
            if (currentSelection != null)
            {
                tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>();
                if (teamFlag != null)
                {
                    teamFlag.SetHighlighted(GetPlayerColor(controlledPlayerIndex));
                }

                // Raise event.

                if (m_OnDeselect != null)
                {
                    m_OnDeselect.Invoke();
                }

                m_Confirmations[controlledPlayerIndex] = false;
            }
        }
    }
    // INTERNALS

    private void BindTo(string i_PlayerName)
    {
        if (StringUtils.IsNullOrEmpty(i_PlayerName))
        {
            return;
        }

        WiFiPlayerInput playerInput = WiFiInputSystem.GetPlayerByNameMain(i_PlayerName);

        m_PlayerInput = playerInput;
    }
    private void Game_Update()
    {
        // Check pause.

        if (!m_Paused)
        {
            if (!m_MatchJustUnpaused)
            {
                bool pausePressed = false;

                InputModule inputModule = UIEventSystem.inputModuleMain;
                if (inputModule != null)
                {
                    for (int index = 0; index < inputModule.playersCount; ++index)
                    {
                        PlayerInput playerInput = inputModule.GetPlayerInput(index);

                        if (playerInput == null)
                        {
                            continue;
                        }

                        pausePressed |= playerInput.GetButtonDown("Pause");
                    }

                    for (int index = 0; index < inputModule.wifiPlayersCount; ++index)
                    {
                        WiFiPlayerInput playerInput = inputModule.GetWifiPlayerInput(index);

                        if (playerInput == null)
                        {
                            continue;
                        }

                        pausePressed |= playerInput.GetButtonDown("Pause");
                    }
                }

                if (pausePressed)
                {
                    if (m_MatchController != null)
                    {
                        bool canPause = m_MatchController.canPause;
                        if (canPause)
                        {
                            m_MatchController.Pause();
                        }
                    }
                }
            }

            m_MatchJustUnpaused = false;
        }
    }
Exemple #11
0
    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);
                    }
                }
            }
        }
    }
Exemple #12
0
    private bool ProcessBackRequests()
    {
        if (m_BackInvoked)
        {
            return(true);
        }

        if (!m_BackRequested)
        {
            bool backRequest = false;

            for (int playerIndex = 0; playerIndex < s_MaxPlayers; ++playerIndex)
            {
                bool backPressed = false;

                PlayerInput playerInput = m_Players[playerIndex];
                if (playerInput != null)
                {
                    backPressed |= playerInput.GetButtonDown(s_PlayerInput_Cancel);
                }
                else
                {
                    WiFiPlayerInput wifiPlayerInput = m_WifiPlayers[playerIndex];
                    if (wifiPlayerInput != null)
                    {
                        backPressed |= wifiPlayerInput.GetButtonDown(s_WiFiPlayerInput_Cancel);
                    }
                }

                backRequest |= backPressed;
                backRequest &= !m_Confirmations[playerIndex];
            }

            if (backRequest)
            {
                m_BackRequested = true;
            }
        }

        if (m_BackRequested && !m_BackInvoked)
        {
            if (m_TriggerCancel != null && m_TriggerCancel.enabled)
            {
                m_TriggerCancel.Invoke();
            }

            m_BackInvoked = true;
        }

        return(m_BackRequested);
    }
Exemple #13
0
    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);
                    }
                }
            }
        }
    }
    public void Frame(WiFiPlayerInput i_PlayerInput)
    {
        if (i_PlayerInput == null)
        {
            return;
        }

        bool move = false;

        move |= i_PlayerInput.GetNegativeButtonDown(s_WiFiPlayerInput_Vertical);
        move |= i_PlayerInput.GetPositiveButtonDown(s_WiFiPlayerInput_Vertical);

        bool submit = i_PlayerInput.GetButtonDown(s_WiFiPlayerInput_Submit);

        InternalUpdate(move, submit);
    }
Exemple #15
0
    private void UpdateSelection(int i_PlayerIndex)
    {
        if (!IsValidIndex(i_PlayerIndex))
        {
            return;
        }

        // Check for selection changes.

        MoveDir moveDirection = MoveDir.None;

        PlayerInput playerInput = m_Players[i_PlayerIndex];

        if (playerInput != null)
        {
            moveDirection = GetMoveDirection(playerInput);
        }
        else
        {
            WiFiPlayerInput wifiPlayerInput = m_WifiPlayers[i_PlayerIndex];
            if (wifiPlayerInput != null)
            {
                moveDirection = GetMoveDirection(wifiPlayerInput);
            }
        }

        if (moveDirection != MoveDir.None)
        {
            IndexList controlledPlayers = m_ControllingMap[i_PlayerIndex];

            int controlledPlayerIndex = controlledPlayers.GetLast();

            if (!IsValidIndex(controlledPlayerIndex))
            {
                return;
            }

            GameObject currentSelection = m_Selections[controlledPlayerIndex];
            Select(controlledPlayerIndex, GetNearest(currentSelection, moveDirection));
        }
    }
        // BUSINESS LOGIC

        public void UpdateTrigger()
        {
            if (!m_CanSend)
            {
                return;
            }

            // Update players action.

            {
                for (int playerInputIndex = 0; playerInputIndex < m_Players.Count; ++playerInputIndex)
                {
                    PlayerInput playerInput = m_Players[playerInputIndex];
                    if (playerInput != null)
                    {
                        if (playerInput.GetButtonDown(m_Action))
                        {
                            m_OnEvent.Invoke();
                        }
                    }
                }
            }

            if (m_UseWifi)
            {
                // Update wifi players action.

                for (int playerInputIndex = 0; playerInputIndex < m_WifiPlayers.Count; ++playerInputIndex)
                {
                    WiFiPlayerInput playerInput = m_WifiPlayers[playerInputIndex];
                    if (playerInput != null)
                    {
                        if (playerInput.GetButtonDown(m_WifiAction))
                        {
                            m_OnEvent.Invoke();
                        }
                    }
                }
            }
        }
    protected override void Awake()
    {
        WiFiInputSystem.InitializeMain();

        for (int index = 0; index < m_Players.Count; ++index)
        {
            PlayerEntry entry = m_Players[index];
            if (entry != null)
            {
                WiFiPlayerInput playerInput = WiFiInputSystem.GetPlayerByNameMain(entry.playerName);
                if (playerInput != null)
                {
                    WiFiPlayer player = new WiFiPlayer(entry.playerName, playerInput);

                    for (int buttonIndex = 0; buttonIndex < entry.buttonsCount; ++buttonIndex)
                    {
                        string button = entry.GetButton(buttonIndex);
                        if (button != "")
                        {
                            player.AddButton(button);
                        }
                    }

                    for (int axisIndex = 0; axisIndex < entry.axesCount; ++axisIndex)
                    {
                        string axis = entry.GetAxis(axisIndex);
                        if (axis != "")
                        {
                            player.AddAxis(axis);
                        }
                    }
                    m_WiFiPlayers.Add(player);
                }
            }
        }
    }
    void Update()
    {
        // Update selection from players.

        {
            for (int playerIndex = 0; playerIndex < m_Players.Count; ++playerIndex)
            {
                PlayerInput playerInput = m_Players[playerIndex];

                if (playerInput == null)
                {
                    continue;
                }

                MoveDir moveDir = GetMoveDirection(playerInput);
                UpdateSelection(moveDir);
            }
        }

        // Update selection from wifi players.

        {
            for (int wifiPlayerIndex = 0; wifiPlayerIndex < m_WiFiPlayers.Count; ++wifiPlayerIndex)
            {
                WiFiPlayerInput wifiPlayerInput = m_WiFiPlayers[wifiPlayerIndex];

                if (wifiPlayerInput == null)
                {
                    continue;
                }

                MoveDir moveDir = GetMoveDirection(wifiPlayerInput);
                UpdateSelection(moveDir);
            }
        }
    }
Exemple #19
0
    private void Game_Update()
    {
        if (PhotonNetwork.room == null)
        {
            if (!m_MatchAborted)
            {
                m_MatchAborted = true;

                if (m_MatchController != null)
                {
                    m_MatchController.MatchBecomeInvalid();
                }
                else
                {
                    OnMatchBecomeInvalid();
                }
            }

            return;
        }

        if (!m_Paused)
        {
            if (!m_MatchJustUnpaused)
            {
                bool pausePressed = false;

                InputModule inputModule = UIEventSystem.inputModuleMain;
                if (inputModule != null)
                {
                    for (int index = 0; index < inputModule.playersCount; ++index)
                    {
                        PlayerInput playerInput = inputModule.GetPlayerInput(index);

                        if (playerInput == null)
                        {
                            continue;
                        }

                        pausePressed |= playerInput.GetButtonDown("Pause");
                    }

                    for (int index = 0; index < inputModule.wifiPlayersCount; ++index)
                    {
                        WiFiPlayerInput playerInput = inputModule.GetWifiPlayerInput(index);

                        if (playerInput == null)
                        {
                            continue;
                        }

                        pausePressed |= playerInput.GetButtonDown("Pause");
                    }
                }

                if (pausePressed)
                {
                    if (m_MatchController != null)
                    {
                        bool canPause = m_MatchController.canPause;
                        if (canPause)
                        {
                            m_MatchController.Pause();
                        }
                    }
                }
            }

            m_MatchJustUnpaused = false;
        }
    }
    void OnEnable()
    {
        // Update players list from InputModule.

        {
            m_Players.Clear();

            InputModule inputModule = UIEventSystem.inputModuleMain;

            if (inputModule != null)
            {
                for (int playerIndex = 0; playerIndex < inputModule.playersCount; ++playerIndex)
                {
                    PlayerInput playerInput = inputModule.GetPlayerInput(playerIndex);
                    m_Players.Add(playerInput);
                }
            }
        }

        // Update wifi players list from InputModule.

        {
            m_WiFiPlayers.Clear();

            InputModule inputModule = UIEventSystem.inputModuleMain;

            if (inputModule != null)
            {
                for (int playerIndex = 0; playerIndex < inputModule.wifiPlayersCount; ++playerIndex)
                {
                    WiFiPlayerInput playerInput = inputModule.GetWifiPlayerInput(playerIndex);
                    m_WiFiPlayers.Add(playerInput);
                }
            }
        }

        // Clear slots.

        {
            for (int entryIndex = 0; entryIndex < m_Entries.Count; ++entryIndex)
            {
                tnUICreditsEntry entry = m_Entries[entryIndex];
                entry.SetHighlighted(false);
            }
        }

        // Clear portrait.

        {
            if (m_Portrait != null)
            {
                m_Portrait.Clear();
            }
        }

        // Find first available entry.

        GameObject firstEntry = null;

        {
            for (int entryIndex = 0; entryIndex < m_Entries.Count; ++entryIndex)
            {
                tnUICreditsEntry creditsEntry = m_Entries[entryIndex];

                if (creditsEntry != null)
                {
                    firstEntry = creditsEntry.gameObject;
                }
            }
        }

        // Update selection.

        {
            Select(firstEntry);
        }
    }
Exemple #21
0
    private void SpawnCharacter(int i_TeamIndex, int i_TeamSize, int i_SpawnIndex, int i_PhotonPlayerId, tnCharacterDescription i_CharacterDescription)
    {
        if (m_CharacterPrefab == null || i_CharacterDescription == null)
        {
            return;
        }

        int descriptorCharacterId       = i_CharacterDescription.characterId;
        int descriptorOnlinePlayerIndex = i_CharacterDescription.onlinePlayerIndex;
        int descriptorPlayerId          = i_CharacterDescription.playerId;

        string[] spawnPointsNames = SpawnPoints.GetSpawnPoints(i_TeamIndex, i_TeamSize);

        if (spawnPointsNames == null)
        {
            return;
        }

        if (i_SpawnIndex < 0 || i_SpawnIndex >= spawnPointsNames.Length)
        {
            return;
        }

        string     spawnPointName = spawnPointsNames[i_SpawnIndex];
        GameObject spawnPointGo   = GameObject.Find(spawnPointName);

        if (spawnPointGo == null)
        {
            return;
        }

        TSTransform2D spawnPoint = spawnPointGo.GetComponent <TSTransform2D>();

        if (spawnPoint == null)
        {
            return;
        }

        tnCharacterData characterData = tnGameData.GetCharacterDataMain(descriptorCharacterId);

        if (characterData == null)
        {
            return;
        }

        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex);

        if (teamDescription == null)
        {
            return;
        }

        int   teamId    = teamDescription.teamId;
        Color teamColor = teamDescription.teamColor;

        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        bool isLocal = (PhotonNetwork.offlineMode) ? true : tnGameModulesUtils.IsLocalPlayer(descriptorOnlinePlayerIndex);
        bool isHuman = (PhotonNetwork.offlineMode) ? (descriptorPlayerId != Hash.s_NULL) : (descriptorOnlinePlayerIndex >= 0);

        Vector3    spawnPosition = spawnPoint.position.ToVector();
        Quaternion spawnRotation = Quaternion.Euler(0f, 0f, spawnPoint.rotation.AsFloat());

        // Spawn character.

        GameObject characterInstance = Instantiate <GameObject>(m_CharacterPrefab);

        characterInstance.name = characterData.displayName;

        characterInstance.transform.position = spawnPosition;
        characterInstance.transform.rotation = spawnRotation;

        // Configure TSTransform

        TSTransform2D tsTransform = characterInstance.GetComponent <TSTransform2D>();

        if (tsTransform != null)
        {
            tsTransform.position = spawnPoint.position;
            tsTransform.rotation = spawnPoint.rotation;
        }

        // Configure depth2d.

        tnDepth2d depth2d = characterInstance.GetComponent <tnDepth2d>();

        if (depth2d != null)
        {
            depth2d.SetOffset(spawnPointGo.transform.position.z);
        }

        // Configure character stats database.

        tnStatsDatabase teamStats = teamData.teamStats;

        tnStatsContainer statsContainer = characterInstance.GetComponent <tnStatsContainer>();

        if (statsContainer != null)
        {
            statsContainer.SetStatsDatabase(teamStats);
        }

        // Configure character view.

        tnCharacterViewController characterViewController = characterInstance.GetComponent <tnCharacterViewController>();

        if (characterViewController != null)
        {
            // Base color.

            characterViewController.SetBaseColor(teamColor);

            // Charging force bar.

            characterViewController.SetChargingForceBarColor(teamColor);

            // Energy bar.

            characterViewController.SetEnergyBarColor(teamColor);

            // Flag.

            characterViewController.SetFlagSprite(teamData.baseSprite);

            // Animator

            characterViewController.SetAnimatorController(characterData.animatorController);

            // Set facing right.

            characterViewController.SetFacingRight((spawnPoint.position.x < 0f));

            // Player color.

            characterViewController.TurnOffColor();
            characterViewController.SetArrowVisible(false);
            characterViewController.SetArrowColor(Color.white);

            if (isLocal)
            {
                if (PhotonNetwork.offlineMode)
                {
                    if (isHuman)
                    {
                        tnPlayerData playerData = tnGameData.GetPlayerDataMain(descriptorPlayerId);
                        if (playerData != null)
                        {
                            Color playerColor = playerData.color;

                            characterViewController.SetPlayerColor(playerColor);

                            characterViewController.SetArrowVisible(true);
                            characterViewController.SetArrowColor(playerColor);
                        }
                    }
                }
                else
                {
                    List <int> onlinePlayersKeys = tnGameData.GetOnlinePlayersKeysMain();
                    if (onlinePlayersKeys != null)
                    {
                        if (descriptorOnlinePlayerIndex >= 0 && descriptorOnlinePlayerIndex < onlinePlayersKeys.Count)
                        {
                            int onlinePlayerKey = onlinePlayersKeys[descriptorOnlinePlayerIndex];
                            tnOnlinePlayerData onlinePlayerData = tnGameData.GetOnlinePlayerDataMain(onlinePlayerKey);
                            if (onlinePlayerData != null)
                            {
                                Color playerColor = onlinePlayerData.color;

                                characterViewController.SetPlayerColor(playerColor);

                                characterViewController.SetArrowVisible(true);
                                characterViewController.SetArrowColor(playerColor);
                            }
                        }
                    }
                }
            }
        }

        // Input: NOTE that current aiFacotry assumes that all AI are handled by the same client.
        // If you want to support AI in multiplayer you should change the ai factory implementation.
        // Now multiplayer isn't implemented, so now, if you're using AI, you are playing offline --> All AIs are yours.

        if (isLocal)
        {
            tnInputFiller      inputFiller      = null;
            tnRumbleController rumbleController = null;

            int  localPlayerIndex;
            bool localPlayerIndexFound = tnGameModulesUtils.OnlineToLocalPlayerIndex(descriptorOnlinePlayerIndex, out localPlayerIndex);
            if (localPlayerIndexFound || PhotonNetwork.offlineMode)
            {
                tnLocalPartyModule localPartyModule = GameModulesManager.GetModuleMain <tnLocalPartyModule>();

                int          playerId   = (PhotonNetwork.offlineMode) ? descriptorPlayerId : ((localPartyModule != null) ? localPartyModule.GetPlayerId(localPlayerIndex) : Hash.s_NULL);
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

                if (playerData != null)
                {
                    string playerInputName     = playerData.playerInputName;
                    string wifiPlayerInputName = playerData.wifiPlayerInputName;

                    PlayerInput     playerInput     = InputSystem.GetPlayerByNameMain(playerInputName);
                    WiFiPlayerInput wifiPlayerInput = WiFiInputSystem.GetPlayerByNameMain(wifiPlayerInputName);

                    if (playerInput != null)
                    {
                        inputFiller      = new tnPlayerInputFiller(playerInput);
                        rumbleController = new tnRumbleController(playerInput);

                        m_LocalPlayersInput.Add(playerInput);
                    }
                    else
                    {
                        if (wifiPlayerInput != null)
                        {
                            inputFiller = new tnWiFiPlayerInputFiller(wifiPlayerInput);

                            m_LocalWifiPlayersInput.Add(wifiPlayerInput);
                        }
                    }
                }
                else
                {
                    tnAIInputFiller aiInputFiller = CreateAIInputFiller(i_TeamIndex, i_SpawnIndex, characterInstance);
                    inputFiller = aiInputFiller;

                    List <tnAIInputFiller> aiList = m_LocalAI[i_TeamIndex];
                    aiList.Add(aiInputFiller);
                }
            }

            // Bind input filler to character instance.

            if (inputFiller != null)
            {
                tnInputController inputController = new tnInputController(inputFiller);
                inputController.SetRumbleController(rumbleController);

                AddInputController(inputController);

                tnCharacterInput characterInput = characterInstance.GetComponent <tnCharacterInput>();
                if (characterInput != null)
                {
                    characterInput.Bind(inputController);
                }
            }

            // Add rumble component.

            if (isHuman)
            {
                tnRumbleParams rumbleParams = Resources.Load <tnRumbleParams>(s_RumbleParams_ResourcePath);

                if (rumbleParams != null)
                {
                    tnRumble rumbleComponent = characterInstance.GetComponent <tnRumble>();
                    if (rumbleComponent == null)
                    {
                        rumbleComponent = characterInstance.AddComponent <tnRumble>();
                    }

                    rumbleComponent.SetParams(rumbleParams);
                }
            }

            // Input Delay.

            int delay = (TrueSyncManager.isOfflineMain) ? m_OfflinePlayerInputDelay : 0;

            if (!isHuman)
            {
                tnMatchSettingsModule matchSettingsModule = GameModulesManager.GetModuleMain <tnMatchSettingsModule>();
                int       aiLevelIndex = (matchSettingsModule != null) ? matchSettingsModule.aiLevelIndex : (tnGameData.aiLevelCountMain / 2);
                tnAILevel aiLevel      = tnGameData.GetAILevelMain(aiLevelIndex);
                if (aiLevel != null)
                {
                    delay = aiLevel.inputDelay;
                }
            }

            // Register on player input collector.

            RegisterObjectOnInputCollector(characterInstance, delay);
        }

        // Configure character info.

        tnCharacterInfo characterInfo = characterInstance.GetComponent <tnCharacterInfo>();

        if (characterInfo == null)
        {
            characterInfo = characterInstance.AddComponent <tnCharacterInfo>();
        }

        int characterIndex = m_Characters.Count;

        characterInfo.SetCharacterIndex(characterIndex);
        characterInfo.SetCharacterId(descriptorCharacterId);
        characterInfo.SetTeamIndex(i_TeamIndex);
        characterInfo.SetTeamId(teamId);
        characterInfo.SetTeamColor(teamColor);

        // Callback.

        OnCharacterSpawned(i_TeamIndex, characterIndex, characterInstance);

        // Add characters to lists.

        m_Characters.Add(characterInstance);
        if (isLocal)
        {
            m_LocalCharacters.Add(characterInstance);
        }

        List <GameObject> team = m_Teams[i_TeamIndex];

        team.Add(characterInstance);

        // Create character result.

        tnCharacterResults characterResults = CreateCharacterResults(descriptorCharacterId);

        characterResults.isHuman = isHuman;

        tnTeamResults teamResults = GetTeamResultsByIndex(i_TeamIndex);

        if (teamResults != null)
        {
            teamResults.AddCharacterResults(characterResults);
        }

        m_CharactersResults.Add(characterResults);

        // Track character result.

        StateTracker.AddTracking(characterResults);

        // Configure TrueSyncObject.

        TrueSyncObject trueSyncObject = characterInstance.GetComponent <TrueSyncObject>();

        if (trueSyncObject != null)
        {
            trueSyncObject.SetOwnerId(i_PhotonPlayerId);
            TrueSyncManager.RegisterTrueSyncObjectMain(trueSyncObject);
        }
    }
        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();
        }
    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);
                        }
                    }
                }
            }
        }
    }