Ejemplo n.º 1
0
    private void UpdatePlayerInputCache(int i_PlayerIndex)
    {
        if (!IsValidIndex(i_PlayerIndex))
        {
            return;
        }

        int playerId = m_Ids[i_PlayerIndex];

        if (playerId == Hash.s_NULL)
        {
            return;
        }

        tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

        if (playerData != null)
        {
            if (!StringUtils.IsNullOrEmpty(playerData.playerInputName))
            {
                m_Players[i_PlayerIndex] = InputSystem.GetPlayerByNameMain(playerData.playerInputName);
            }
            else
            {
                if (!StringUtils.IsNullOrEmpty(playerData.wifiPlayerInputName))
                {
                    m_WifiPlayers[i_PlayerIndex] = WiFiInputSystem.GetPlayerByNameMain(playerData.wifiPlayerInputName);
                }
            }
        }
    }
    public tnPlayerData GetData(int i_Id)
    {
        tnPlayerData data = null;

        m_Data.TryGetValue(i_Id, out data);
        return(data);
    }
Ejemplo n.º 3
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);
    }
    // LOGIC

    public void Initialize(string i_DatabasePath)
    {
        tnPlayersDatabase database = Resources.Load <tnPlayersDatabase>(i_DatabasePath);

        if (database != null)
        {
            for (int index = 0; index < database.playersCount; ++index)
            {
                tnPlayerDataEntry entry = database.GetPlayerDataEntry(index);
                if (entry != null)
                {
                    string key = entry.id;
                    tnPlayerDataDescriptor descriptor = entry.descriptor;
                    if (key != "" && descriptor != null)
                    {
                        int          hash = StringUtils.GetHashCode(key);
                        tnPlayerData data = new tnPlayerData(descriptor);

                        m_Data.Add(hash, data);
                        m_Keys.Add(hash);
                    }
                }
            }
        }
        else
        {
            LogManager.LogWarning(this, "Database not loaded.");
        }
    }
    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);
                }
            }
        }
    }
Ejemplo n.º 6
0
    private string GetPlayerNameById(int i_PlayerId)
    {
        if (i_PlayerId != Hash.s_NULL)
        {
            tnPlayerData playerData = tnGameData.GetPlayerDataMain(i_PlayerId);
            if (playerData != null)
            {
                return(playerData.name);
            }
        }

        return(StringUtils.s_NULL); // Invalid player.
    }
Ejemplo n.º 7
0
    private Color GetPlayerColorById(int i_PlayerId)
    {
        if (i_PlayerId != Hash.s_NULL)
        {
            tnPlayerData playerData = tnGameData.GetPlayerDataMain(i_PlayerId);
            if (playerData != null)
            {
                return(playerData.color);
            }
        }

        return(Color.white); // Invalid player.
    }
Ejemplo n.º 8
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);
                    }
                }
            }
        }
    }
    // INTERNALS

    private void RefreshView()
    {
        tnPlayerData playerData = tnGameData.GetPlayerDataMain(m_PlayerId);

        bool hasValidPlayer = (playerData != null);

        if (hasValidPlayer)
        {
            PlayerInput     playerInput;
            WiFiPlayerInput wifiPlayerInput;
            tnInputUtils.GetPlayersInputs(m_PlayerId, out playerInput, out wifiPlayerInput);

            bool joystick = (playerInput != null) ? (playerInput.JoystickCount > 0) : false;
            bool keyboard = (playerInput != null) ? (playerInput.JoystickCount == 0) : false;
            bool phone    = (wifiPlayerInput != null) ? true : false;

            SetImageActive(true);
            if (joystick)
            {
                SetImageSprite(m_Controller);
            }
            if (keyboard)
            {
                SetImageSprite(m_Keyboard);
            }
            if (phone)
            {
                SetImageSprite(m_Phone);
            }

            SetPlayerNameActive(true);

            SetOverlayText("");
            SetOverlayTextActive(false);

            Color color = playerData.color;
            SetColor(color);
        }
        else
        {
            SetImageActive(false);

            SetPlayerName("");
            SetPlayerNameActive(false);

            SetOverlayText(s_DefaultText);
            SetOverlayTextActive(true);

            SetColor(Color.white);
        }
    }
Ejemplo n.º 10
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);
                    }
                }
            }
        }
    }
Ejemplo n.º 11
0
    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);
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 12
0
    // INTERNALS

    private void SelectPlayer(int i_TeamIndex)
    {
        tnTeamsModule teamsModule = GameModulesManager.GetModuleMain <tnTeamsModule>();

        if (teamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = teamsModule.GetTeamDescription(i_TeamIndex);

        if (teamDescription != null)
        {
            int playerId = teamDescription.captainPlayerId;
            m_Ids[i_TeamIndex] = playerId;

            // Cache PlayerInput.

            tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);
            if (playerData != null)
            {
                if (!StringUtils.IsNullOrEmpty(playerData.playerInputName))
                {
                    m_Players[i_TeamIndex] = InputSystem.GetPlayerByNameMain(playerData.playerInputName);

                    PushControllingMap(i_TeamIndex, i_TeamIndex);
                }
                else
                {
                    if (!StringUtils.IsNullOrEmpty(playerData.wifiPlayerInputName))
                    {
                        m_WifiPlayers[i_TeamIndex] = WiFiInputSystem.GetPlayerByNameMain(playerData.wifiPlayerInputName);

                        PushControllingMap(i_TeamIndex, i_TeamIndex);
                    }
                }
            }
        }

        // Update image and label.

        UpdateImageColor(i_TeamIndex);
        UpdateLabel(i_TeamIndex);
    }
    // tnBaseStandardMatchAIFactory's interface

    protected override void OnConfigure(tnTeamDescription i_TeamDescription)
    {
        if (i_TeamDescription == null)
        {
            return;
        }

        int charactersCount = i_TeamDescription.charactersCount;

        if (charactersCount <= 0 || charactersCount >= s_Roles.Length)
        {
            return;
        }

        AIRole[] roles = s_Roles[charactersCount - 1];

        if (roles == null || roles.Length == 0 || roles.Length != charactersCount)
        {
            return;
        }

        int aiIndex = 0;

        for (int characterIndex = 0; characterIndex < charactersCount; ++characterIndex)
        {
            tnCharacterDescription characterDescription = i_TeamDescription.GetCharacterDescription(characterIndex);

            if (characterDescription == null)
            {
                continue;
            }

            int          playerId   = characterDescription.playerId;
            tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);

            if (playerData == null)
            {
                AIRole role = roles[aiIndex++];
                m_Roles.Add(role);
            }
        }

        m_Roles.Sort();
    }
        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);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 15
0
    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);
                            }
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 16
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);
        }
    }
    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);
                        }
                    }
                }
            }
        }
    }
    private void FillAttractTimeData(int i_SlotIndex, tnBaseMatchController i_MatchController)
    {
        if (i_MatchController == null)
        {
            return;
        }

        int charcatersCount = i_MatchController.charactersCount;

        // Compute total shots count.

        FP totalAttractTime = FP.Zero;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                totalAttractTime += characterResults.attractTime;
            }
        }

        // Get best character for this stat.

        int selectedCharacterIndex = -1;

        int selectedCharacterId = Hash.s_NULL;
        int selectedPlayerId    = Hash.s_NULL;

        FP maxAttractTime = FP.MinValue;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                FP characterAttractTime = characterResults.attractTime;

                if (characterAttractTime > maxAttractTime)
                {
                    selectedCharacterIndex = characterIndex;

                    selectedCharacterId = characterResults.id;
                    selectedPlayerId    = characterResults.playerId;

                    maxAttractTime = characterAttractTime;
                }
            }
        }

        if (selectedCharacterIndex < 0)
        {
            return;
        }

        // Fill data.

        string playerName     = "";
        Sprite playerPortrait = null;

        Color playerColor = Color.white;

        {
            tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId);
            if (characterData != null)
            {
                playerName     = characterData.displayName;
                playerPortrait = characterData.uiIconFacingRight;
            }

            tnPlayerData playerData = tnGameData.GetPlayerDataMain(selectedPlayerId);
            if (playerData != null)
            {
                playerColor = playerData.color;
            }
        }

        string statValue = maxAttractTime.ToString(2);

        statValue += " s";

        FP partecipationPercentage = FP.Zero;

        if (totalAttractTime > FP.Zero)
        {
            partecipationPercentage  = maxAttractTime / totalAttractTime;
            partecipationPercentage *= 100f;

            partecipationPercentage = MathFP.Clamp(partecipationPercentage, FP.Zero, 100f);
        }

        string partecipationValue = partecipationPercentage.ToString(2);

        partecipationValue += "%";

        FillData(i_SlotIndex, playerName, playerPortrait, playerColor, s_StatName_AttractTime, statValue, s_PartecipationLabel, partecipationValue);
    }
    private void SpawnPhones()
    {
        if (m_UIPhonePrefab == null)
        {
            return;
        }

        if (m_ControllersGrid == null)
        {
            return;
        }

        if (m_ControllersRoot == null)
        {
            return;
        }

        List <int> playersKeys = tnGameData.GetPlayersKeysMain();

        if (playersKeys == null)
        {
            return;
        }

        int playersCount = WiFiInputSystem.playersCountMain;
        int max          = Mathf.Min(playersCount, playersKeys.Count);

        for (int index = 0; index < max; ++index)
        {
            ControllerAnchor anchor = m_ControllersGrid.GetAnchorByIndex(index + m_Gamepads.Count);
            if (anchor != null)
            {
                int playerIndex = index + m_Gamepads.Count;

                if (playerIndex >= playersKeys.Count)
                {
                    continue;
                }

                int          playerId   = playersKeys[playerIndex];
                tnPlayerData playerData = tnGameData.GetPlayerDataMain(playerId);
                if (playerData != null)
                {
                    tnUIPhone phone = GameObject.Instantiate <tnUIPhone>(m_UIPhonePrefab);
                    phone.transform.SetParent(m_ControllersRoot, false);

                    phone.SetPlayerId(playerId);
                    phone.SetPlayerName(playerData.wifiPlayerInputName);

                    phone.SetDefaultAnchor(anchor);

                    phone.gameObject.name = playerData.name + "_Phone";
                    Color color = playerData.color;
                    phone.SetColor(color, true);

                    phone.SetTeamsManagers(m_TeamA, m_TeamB);

                    phone.hasFocus = false;

                    m_Phones.Add(phone);
                }
            }
        }
    }
    private void FillGoalScoredData(int i_SlotIndex, tnBaseMatchController i_MatchController)
    {
        if (i_MatchController == null)
        {
            return;
        }

        int charcatersCount = i_MatchController.charactersCount;

        // Compute total shots count.

        int totalGoalScored = 0;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                totalGoalScored += characterResults.goalScored;
            }
        }

        // Get best character for this stat.

        int selectedCharacterIndex = -1;

        int selectedCharacterId = Hash.s_NULL;
        int selectedPlayerId    = Hash.s_NULL;

        int maxGoalScored = int.MinValue;

        for (int characterIndex = 0; characterIndex < charcatersCount; ++characterIndex)
        {
            tnBaseMatchCharacterResults characterResults = (tnBaseMatchCharacterResults)i_MatchController.GetCharacterResultsByIndex(characterIndex);
            if (characterResults != null)
            {
                int characterGoalScored = characterResults.goalScored;

                if (characterGoalScored > maxGoalScored)
                {
                    selectedCharacterIndex = characterIndex;

                    selectedCharacterId = characterResults.id;
                    selectedPlayerId    = characterResults.playerId;

                    maxGoalScored = characterGoalScored;
                }
            }
        }

        if (selectedCharacterIndex < 0)
        {
            return;
        }

        // Fill data.

        string playerName     = "";
        Sprite playerPortrait = null;

        Color playerColor = Color.white;

        {
            tnCharacterData characterData = tnGameData.GetCharacterDataMain(selectedCharacterId);
            if (characterData != null)
            {
                playerName     = characterData.displayName;
                playerPortrait = characterData.uiIconFacingRight;
            }

            tnPlayerData playerData = tnGameData.GetPlayerDataMain(selectedPlayerId);
            if (playerData != null)
            {
                playerColor = playerData.color;
            }
        }

        string statValue = maxGoalScored.ToString();

        float partecipationPercentage = 0f;

        if (totalGoalScored > 0)
        {
            partecipationPercentage  = (float)maxGoalScored / (float)totalGoalScored;
            partecipationPercentage *= 100f;

            partecipationPercentage = Mathf.Clamp(partecipationPercentage, 0f, 100f);
        }

        string partecipationValue = partecipationPercentage.ToString("0.00");

        partecipationValue += "%";

        FillData(i_SlotIndex, playerName, playerPortrait, playerColor, s_StatName_GoalScored, statValue, s_PartecipationLabel, partecipationValue);
    }