private void ClearLineUp(int i_TeamIndex) { if (!IsValidIndex(i_TeamIndex)) { return; } SlotList slotList = m_LineUp[i_TeamIndex]; for (int index = 0; index < slotList.Count; ++index) { tnUICharacterSlot slot = slotList[index]; if (slot != null) { tnUICharacter character = slot.character; RecycleCharacter(character); slot.Clear(); } RecycleCharacterSlot(slot); } slotList.Clear(); }
// UTILITIES private void InitializePool() { int poolSize = 2 * s_TeamSize; if (m_CharacterPrefab != null && m_CharactersRoot != null) { for (int index = 0; index < poolSize; ++index) { tnUICharacter characterInstance = GameObject.Instantiate <tnUICharacter>(m_CharacterPrefab); characterInstance.transform.SetParent(m_CharactersRoot, false); characterInstance.gameObject.SetActive(false); m_CharactersPool.Add(characterInstance); } } if (m_CharacterSlotPrefab != null && m_SlotsRoot != null) { for (int index = 0; index < poolSize; ++index) { tnUICharacterSlot characterSlot = GameObject.Instantiate <tnUICharacterSlot>(m_CharacterSlotPrefab); characterSlot.transform.SetParent(m_SlotsRoot, false); characterSlot.gameObject.SetActive(false); m_CharactersSlotsPool.Add(characterSlot); } } }
private void RecycleCharacter(tnUICharacter i_Character) { if (i_Character == null) { return; } i_Character.Clear(); i_Character.gameObject.SetActive(false); m_CharactersPool.Add(i_Character); }
public void Clear() { m_CharacterId = Hash.s_NULL; m_Character = null; m_Selected = false; m_Highlighted = false; m_HighlightColor = Color.white; m_HasPlayerColor = false; m_PlayerColor = Color.white; }
private void Swap(tnUICharacterSlot i_A, tnUICharacterSlot i_B) { if (i_A == null || i_B == null || i_A == i_B) { return; } int tempCharacterId = i_A.characterId; i_A.characterId = i_B.characterId; i_B.characterId = tempCharacterId; tnUICharacter tempCharacter = i_A.character; i_A.character = i_B.character; i_B.character = tempCharacter; }
private tnUICharacter SpawnCharacter(tnCharacterData i_CharacterData, FacingDir i_Facing, Color i_TeamColor, Sprite i_Flag) { tnUICharacter character = null; if (m_CharactersPool.Count > 0) { character = m_CharactersPool[m_CharactersPool.Count - 1]; m_CharactersPool.RemoveAt(m_CharactersPool.Count - 1); character.gameObject.SetActive(true); } else { if (m_CharacterPrefab == null) { return(null); } character = GameObject.Instantiate <tnUICharacter>(m_CharacterPrefab); character.transform.SetParent(transform, false); } character.SetBaseColor(i_TeamColor); character.SetFlagSprite(i_Flag); if (i_Facing == FacingDir.FacingRight) { character.SetCharacterSprite(i_CharacterData.uiIconFacingRight); } else // Facing Left { character.SetCharacterSprite(i_CharacterData.uiIconFacingLeft); } character.SetName(i_CharacterData.displayName); character.SetAvailable(); character.Deselect(); return(character); }
// 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); } } } }