public tnUIBenchEntry GetFirstAvailableEntry()
    {
        for (int index = 0; index < m_Entries.Count; ++index)
        {
            tnUIBenchEntry entry = m_Entries[index];
            if (entry != null)
            {
                if (entry.isFree)
                {
                    return(entry);
                }
            }
        }

        return(null);
    }
    public tnUIBenchEntry GetLastAvailableEntry()
    {
        for (int index = m_Entries.Count - 1; index >= 0; --index)
        {
            tnUIBenchEntry entry = m_Entries[index];
            if (entry != null)
            {
                if (entry.isFree)
                {
                    return(entry);
                }
            }
        }

        return(null);
    }
Exemplo n.º 3
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);
                }
            }
        }
    }