예제 #1
0
    // LOGIC

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

        if (database != null)
        {
            for (int index = 0; index < database.teamsCount; ++index)
            {
                tnTeamDataEntry entry = database.GetTeamDataEntry(index);
                if (entry != null)
                {
                    string key = entry.id;
                    tnTeamDataDescriptor descriptor = entry.descriptor;
                    if (key != "" && descriptor != null)
                    {
                        int        hash = StringUtils.GetHashCode(key);
                        tnTeamData data = new tnTeamData(descriptor);

                        m_Data.Add(hash, data);
                        m_Keys.Add(hash);
                    }
                }
            }
        }
        else
        {
            LogManager.LogWarning(this, "Database not loaded.");
        }
    }
예제 #2
0
    public tnTeamData GetData(int i_Id)
    {
        tnTeamData data = null;

        m_Data.TryGetValue(i_Id, out data);
        return(data);
    }
        private tnTeamDescription CreateTeam(int i_TeamKey, int i_TeamSize, Color i_TeamColor)
        {
            tnTeamData teamData = tnGameData.GetTeamDataMain(i_TeamKey);

            if (teamData == null || i_TeamSize <= 0)
            {
                return(null);
            }

            tnTeamDescription teamDescription = new tnTeamDescription();

            teamDescription.SetTeamId(i_TeamKey);
            teamDescription.SetTeamColor(i_TeamColor);

            List <int> teamLineup = teamData.GetDefaultLineUp(i_TeamSize);

            for (int characterIndex = 0; characterIndex < teamLineup.Count; ++characterIndex)
            {
                int characterKey = teamLineup[characterIndex];

                tnCharacterDescription characterDescription = new tnCharacterDescription();
                characterDescription.SetCharacterId(characterKey);
                characterDescription.SetPlayerId(StringUtils.s_NULL);
                characterDescription.SetSpawnOrder(characterIndex);

                teamDescription.AddCharacterDescription(characterDescription);
            }

            return(teamDescription);
        }
    public void AddTeamFlag(tnTeamData i_TeamData)
    {
        if (i_TeamData != null)
        {
            Sprite sprite = i_TeamData.flag;
            string name   = i_TeamData.name;

            if (m_TeamEntryPrefab != null && m_FlagsContent != null)
            {
                tnTeamFlag teamFlag = m_TeamEntryPrefab.Spawn <tnTeamFlag>();

                teamFlag.transform.SetParent(m_FlagsContent, false);

                if (sprite != null)
                {
                    teamFlag.SetImage(sprite);
                }

                teamFlag.SetLabel(name);
                teamFlag.SetAvailable();

                m_Slots.Add(teamFlag.gameObject);
            }
        }
    }
예제 #5
0
    public void Bind(tnStandardMatchController i_MatchController)
    {
        m_MatchController = i_MatchController;

        // Team 0 - Flag.

        int team0Id = m_MatchController.GetTeamId(0);

        tnTeamData team0Data = tnGameData.GetTeamDataMain(team0Id);

        if (team0Data != null)
        {
            SetFlagTeam0(team0Data.icon);
        }

        // Team 1 - Flag.

        int team1Id = m_MatchController.GetTeamId(1);

        tnTeamData team1Data = tnGameData.GetTeamDataMain(team1Id);

        if (team1Data != null)
        {
            SetFlagTeam1(team1Data.icon);
        }
    }
    // INTERNALS

    private void InternalSetResults(tnSubbuteoMatchController i_MathController)
    {
        if (i_MathController == null)
        {
            return;
        }

        // Team 0

        tnSubbuteoMatchTeamResults teamResults0 = (tnSubbuteoMatchTeamResults)i_MathController.GetTeamResultsByIndex(0);

        if (teamResults0 != null)
        {
            int        teamId0   = teamResults0.id;
            tnTeamData teamData0 = tnGameData.GetTeamDataMain(teamId0);

            if (m_Team0Flag != null)
            {
                m_Team0Flag.sprite = teamData0.flag;
            }

            if (m_Team0Name != null)
            {
                m_Team0Name.text = teamData0.name;
            }

            if (m_Team0Score != null)
            {
                m_Team0Score.text = teamResults0.score.ToString();
            }
        }

        // Team 1

        tnSubbuteoMatchTeamResults teamResults1 = (tnSubbuteoMatchTeamResults)i_MathController.GetTeamResultsByIndex(1);

        if (teamResults1 != null)
        {
            int        teamId1   = teamResults1.id;
            tnTeamData teamData1 = tnGameData.GetTeamDataMain(teamId1);

            if (m_Team1Flag != null)
            {
                m_Team1Flag.sprite = teamData1.flag;
            }

            if (m_Team1Name != null)
            {
                m_Team1Name.text = teamData1.name;
            }

            if (m_Team1Score != null)
            {
                m_Team1Score.text = teamResults1.score.ToString();
            }
        }
    }
예제 #7
0
    // UTILS

    protected Color[] GetTeamColors(int i_TeamId)
    {
        tnTeamData teamData = tnGameData.GetTeamDataMain(i_TeamId);

        if (teamData != null)
        {
            Color[] teamColors = new Color[2]; // First/Second color.

            teamColors[0] = teamData.supportersFirstColor;
            teamColors[1] = teamData.supportersSecondColor;

            return(teamColors);
        }

        return(null);
    }
    public void AddTeam(int i_TeamId)
    {
        if (viewInstance == null)
        {
            return;
        }

        tnTeamData teamData = tnGameData.GetTeamDataMain(i_TeamId);

        if (teamData == null)
        {
            return;
        }

        viewInstance.AddTeamFlag(teamData);
        m_TeamsIds.Add(i_TeamId);
    }
예제 #9
0
    private void SetTeamInfo(int i_TeamIndex, tnTeamData i_TeamData)
    {
        if (!IsValidIndex(i_TeamIndex))
        {
            return;
        }

        if (i_TeamData == null)
        {
            return;
        }

        tnUITeamInfo teamInfo = m_TeamInfo[i_TeamIndex];

        if (teamInfo != null)
        {
            teamInfo.SetFlag(i_TeamData.flag);
            teamInfo.SetName(i_TeamData.name);
        }
    }
    private void Internal_AddTeamB(tnTeamsModule i_TeamsModule, int i_CharacterCount)
    {
        if (i_TeamsModule == null)
        {
            return;
        }

        tnTeamDescription teamDescription = new tnTeamDescription();

        string teamId = GetTeamB();

        teamDescription.SetTeamId(teamId);

        Color teamColor = GetTeamBColor();

        teamDescription.SetTeamColor(teamColor);

        if (i_CharacterCount >= 0)
        {
            tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);
            if (teamData != null)
            {
                int characterCount = Mathf.Min(i_CharacterCount, teamData.charactersCount);
                for (int index = 0; index < characterCount; ++index)
                {
                    tnCharacterDescription characterDescription = new tnCharacterDescription();
                    characterDescription.SetCharacterId(teamData.GetCharacterKey(index));
                    characterDescription.SetSpawnOrder(index);

                    if (m_AllHumans)
                    {
                        characterDescription.SetPlayerId(GetPlayerIdByIndex(index + characterCount));
                    }

                    teamDescription.AddCharacterDescription(characterDescription);
                }
            }
        }

        i_TeamsModule.AddTeamDescription(teamDescription);
    }
    // LOGIC

    public void Config(tnSubbuteoMatchController i_Controller)
    {
        if (viewInstance != null)
        {
            if (i_Controller == null)
            {
                return;
            }

            // Team 0

            tnSubbuteoMatchTeamResults teamResults0 = (tnSubbuteoMatchTeamResults)i_Controller.GetTeamResultsByIndex(0);
            if (teamResults0 != null)
            {
                int        teamId0   = teamResults0.id;
                tnTeamData teamData0 = tnGameData.GetTeamDataMain(teamId0);

                string name  = teamData0.name;
                int    score = teamResults0.score;
                Sprite flag  = teamData0.flag;

                viewInstance.SetTeam0(name, score, flag);
            }

            // Team 1

            tnSubbuteoMatchTeamResults teamResults1 = (tnSubbuteoMatchTeamResults)i_Controller.GetTeamResultsByIndex(1);
            if (teamResults1 != null)
            {
                int        teamId1   = teamResults1.id;
                tnTeamData teamData1 = tnGameData.GetTeamDataMain(teamId1);

                string name  = teamData1.name;
                int    score = teamResults1.score;
                Sprite flag  = teamData1.flag;

                viewInstance.SetTeam1(name, score, flag);
            }
        }
    }
        public static Color[] ComputeTeamColors(int[] i_TeamIds)
        {
            if (i_TeamIds == null || i_TeamIds.Length == 0)
            {
                return(null);
            }

            Color[] teamColors = new Color[i_TeamIds.Length];

            for (int teamIndex = 0; teamIndex < i_TeamIds.Length; ++teamIndex)
            {
                teamColors[teamIndex] = Color.white;

                int teamId = i_TeamIds[teamIndex];

                tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);
                if (teamData != null)
                {
                    Color firstColor  = teamData.firstColor;
                    Color secondColor = teamData.secondColor;

                    teamColors[teamIndex] = firstColor;

                    for (int prevIndex = 0; prevIndex < teamIndex; ++prevIndex)
                    {
                        if (ColorUtils.ApproximatelyEqual(teamColors[prevIndex], teamColors[teamIndex], 0.1f, 0.1f, 0.1f, 1f))
                        {
                            teamColors[teamIndex] = secondColor;
                            break;
                        }
                    }
                }
            }

            return(teamColors);
        }
예제 #13
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);
        }
    }
예제 #14
0
    private void ProceesTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (i_TeamDescription == null)
        {
            return;
        }

        int        teamId   = i_TeamDescription.teamId;
        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        m_TeamsIds.Add(teamId);

        // Get team size.

        int teamSize = i_TeamDescription.charactersCount;

        // Create team results.

        tnTeamResults teamResults = CreateTeamResults(teamId);

        m_TeamsResults.Add(teamResults);

        StateTracker.AddTracking(teamResults);

        // Callback.

        OnCreateTeam(i_TeamIndex, i_TeamDescription);

        for (int characterIndex = 0; characterIndex < teamSize; ++characterIndex)
        {
            tnCharacterDescription characterDescription = (PhotonNetwork.offlineMode) ? i_TeamDescription.GetCharacterDescriptionBySpawnOrder(characterIndex) : i_TeamDescription.GetCharacterDescription(characterIndex);

            if (characterDescription == null)
            {
                continue;
            }

            int disconnectedPlayerPhotonId = -1;
            int photonPlayerId;
            if (PhotonNetwork.offlineMode)
            {
                photonPlayerId = 0; // 0 is the default value related to a fake "Local_Player". See TrueSyncController::Initialize.
            }
            else
            {
                int onlinePlayerIndex = characterDescription.onlinePlayerIndex;
                tnGameModulesUtils.GetPhotonPlayerOwnerId(onlinePlayerIndex, out photonPlayerId);

                // Check if the owner of this character is still connected. If not, reset photon player id.

                PhotonPlayer owner = PhotonUtils.GetPhotonPlayer(photonPlayerId);
                disconnectedPlayerPhotonId = (owner == null) ? photonPlayerId : -1;
                photonPlayerId             = (owner != null) ? photonPlayerId : -1;
            }

            // If photon player id is valid, spawn character.

            if (photonPlayerId >= 0)
            {
                SpawnCharacter(i_TeamIndex, teamSize, characterIndex, photonPlayerId, characterDescription);
            }
            else
            {
                Debug.LogWarning("[tnMatchController] Character skipped for photon player id " + disconnectedPlayerPhotonId + ".");
            }
        }
    }
예제 #15
0
    // MonoBehaviour's INTERFACE

    void Awake()
    {
        // Initialize Controlling map.

        for (int index = 0; index < s_MaxPlayers; ++index)
        {
            IndexList indexList = new IndexList();
            m_ControllingMap.Add(indexList);
        }

        // Get widgets.

        UIPageDescriptor pageDescriptor = GetComponentInChildren <UIPageDescriptor>();

        if (pageDescriptor != null)
        {
            m_TriggerProceed = pageDescriptor.GetWidget <UIEventTrigger>(s_WidgetId_ProceedTrigger);
            m_TriggerCancel  = pageDescriptor.GetWidget <UIEventTrigger>(s_WidgetId_CancelTrigger);
        }

        // Create and setup slots.

        if (m_LayoutGroup == null || m_SlotPrefab == null)
        {
            return;
        }

        // Configure grid layout.

        RectTransform slotPrefabTransform = m_SlotPrefab.GetComponent <RectTransform>();

        if (slotPrefabTransform != null)
        {
            m_LayoutGroup.cellSize = new Vector2(slotPrefabTransform.rect.width, slotPrefabTransform.rect.height);
        }

        // Spawn slots.

        List <int> teamKeys = tnGameData.GetTeamsKeysMain();

        foreach (int key in teamKeys)
        {
            GameObject slotInstance = (GameObject)Instantiate(m_SlotPrefab);
            slotInstance.SetParent(m_LayoutGroup.gameObject, true);

            tnTeamFlag teamFlag = slotInstance.GetComponent <tnTeamFlag>();
            if (teamFlag != null)
            {
                // Set Team Id.

                teamFlag.SetTeamId(key);

                // Set flag image and team name.

                tnTeamData teamData = tnGameData.GetTeamDataMain(key);
                teamFlag.SetImage(teamData.flag);
                teamFlag.SetLabel(teamData.name);
            }

            m_Slots.Add(slotInstance);
        }
    }
예제 #16
0
    // INTERNAL

    private void Internal_SetupTeam(int i_TeamIndex, tnTeamDescription i_TeamDescription)
    {
        if (!IsValidIndex(i_TeamIndex))
        {
            return;
        }

        if (i_TeamDescription == null)
        {
            return;
        }

        int        teamId   = i_TeamDescription.teamId;
        tnTeamData teamData = tnGameData.GetTeamDataMain(teamId);

        if (teamData == null)
        {
            return;
        }

        List <int> lineUp = teamData.GetDefaultLineUp(i_TeamDescription.charactersCount);

        if (lineUp == null)
        {
            return;
        }

        SetTeamInfo(i_TeamIndex, teamData);

        // Lineup.

        {
            tnUITeamAnchors teamAnchors = m_TeamAnchorsSets[i_TeamIndex];

            tnUIAnchorsSet anchorsSet = null;

            if (teamAnchors != null)
            {
                anchorsSet = teamAnchors.GetAnchorsSetBySize(i_TeamDescription.charactersCount);
            }

            if (anchorsSet != null)
            {
                for (int index = 0; index < anchorsSet.anchorsCount && index < lineUp.Count; ++index)
                {
                    RectTransform anchor = anchorsSet.GetAnchorByIndex(index);
                    if (anchor != null)
                    {
                        int characterId = lineUp[index];

                        if (!teamData.Contains(characterId))
                        {
                            continue;
                        }

                        tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                        if (characterData == null)
                        {
                            continue;
                        }

                        FacingDir facingDir = m_Facing[i_TeamIndex];

                        Color  teamColor = i_TeamDescription.teamColor;
                        Sprite flag      = teamData.baseSprite;

                        tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                        tnUICharacterSlot slot = SpawnCharacterSlot();
                        slot.transform.position = anchor.position;
                        slot.character          = character;
                        slot.characterId        = characterId;

                        bool isHuman = m_Humans[i_TeamIndex, index];
                        if (isHuman)
                        {
                            Color playerColor = m_PlayersColors[i_TeamIndex, index];
                            slot.SetPlayerColor(playerColor);
                        }
                        else
                        {
                            slot.ClearPlayerColor();
                        }

                        SlotList slotList = m_LineUp[i_TeamIndex];
                        slotList.Add(slot);
                    }
                }
            }

            m_TeamAnchors[i_TeamIndex] = anchorsSet;
        }

        // Bench.

        {
            tnUIBench bench = m_TeamAnchorsBench[i_TeamIndex];

            int lastBenchIndexUsed = -1;
            for (int index = 0; index < bench.entriesCount && index < teamData.charactersCount; ++index)
            {
                tnUIBenchEntry benchEntry = bench.GetEntryByIndex(index);
                if (benchEntry != null && benchEntry.anchor != null)
                {
                    int characterId = Hash.s_NULL;

                    for (int characterIndex = lastBenchIndexUsed + 1; characterIndex < teamData.charactersCount; ++characterIndex)
                    {
                        int id = teamData.GetCharacterKey(characterIndex);
                        if (!lineUp.Contains(id))
                        {
                            characterId        = id;
                            lastBenchIndexUsed = characterIndex;
                            break;
                        }
                    }

                    tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId);

                    if (characterData == null)
                    {
                        continue;
                    }

                    FacingDir facingDir = m_Facing[i_TeamIndex];

                    Color  teamColor = i_TeamDescription.teamColor;
                    Sprite flag      = teamData.baseSprite;

                    tnUICharacter character = SpawnCharacter(characterData, facingDir, teamColor, flag);

                    tnUICharacterSlot slot = SpawnCharacterSlot();
                    slot.transform.position = benchEntry.anchor.position;
                    slot.character          = character;
                    slot.characterId        = characterId;
                    slot.ClearPlayerColor();

                    SlotList slotList = m_Bench[i_TeamIndex];
                    slotList.Add(slot);
                }
            }
        }
    }