private bool IsAvailable(GameObject i_Slot, int i_PlayerIndex) { if (i_Slot == null) { return(false); } tnUICharacterSlot slot = i_Slot.GetComponent <tnUICharacterSlot>(); if (slot != null) { SlotList lineUp = m_LineUp[i_PlayerIndex]; SlotList bench = m_Bench[i_PlayerIndex]; if (lineUp.Contains(slot) || bench.Contains(slot)) { if (slot.character != null) { return(true); } } } return(false); }
private void Select(int i_TeamIndex, int i_SlotIndex) { if (!IsValidIndex(i_TeamIndex)) { return; } SlotList lineUp = m_LineUp[i_TeamIndex]; SlotList bench = m_Bench[i_TeamIndex]; if (i_SlotIndex < 0 || i_SlotIndex >= lineUp.Count + bench.Count) { return; } else { if (i_SlotIndex < lineUp.Count) { tnUICharacterSlot slot = lineUp[i_SlotIndex]; if (slot != null) { Select(i_TeamIndex, slot.gameObject); } } else { i_SlotIndex = i_SlotIndex % lineUp.Count; tnUICharacterSlot slot = bench[i_SlotIndex]; if (slot != null) { Select(i_TeamIndex, slot.gameObject); } } } }
public List <int> GetLineUpIds(int i_TeamIndex) { List <int> charactersIds = new List <int>(); if (IsValidIndex(i_TeamIndex)) { List <tnUICharacterSlot> slots = m_LineUp[i_TeamIndex]; if (slots != null) { for (int characterIndex = 0; characterIndex < slots.Count; ++characterIndex) { tnUICharacterSlot slot = slots[characterIndex]; if (slot == null) { continue; } int id = slot.characterId; charactersIds.Add(id); } } } return(charactersIds); }
private void ClearBench(int i_TeamIndex) { if (!IsValidIndex(i_TeamIndex)) { return; } SlotList slotList = m_Bench[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(); }
public void Ready(int i_TeamIndex) { if (IsValidIndex(i_TeamIndex)) { if (!IsReady(i_TeamIndex)) { // Cancel current selection, if any. SelectionCache cache = m_SelectionsCache[i_TeamIndex]; if (!cache.IsEmpty()) { GameObject lastSelection = cache[0]; if (lastSelection != null) { tnUICharacterSlot slot = lastSelection.GetComponent <tnUICharacterSlot>(); if (slot != null) { slot.Deselect(); } } cache.Clear(); } m_Confirmations[i_TeamIndex] = true; UpdateOverlay(i_TeamIndex); SfxPlayer.PlayMain(m_ReadySfx); } } }
// 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 RecycleCharacterSlot(tnUICharacterSlot i_Slot) { if (i_Slot == null) { return; } i_Slot.Clear(); i_Slot.gameObject.SetActive(false); m_CharactersSlotsPool.Add(i_Slot); }
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 void Select(int i_TeamIndex, GameObject i_Slot) { if (!IsValidIndex(i_TeamIndex)) { return; } if (i_Slot == null) { return; } // Release previous selection. { GameObject currentSlot = m_CurrentSlots[i_TeamIndex]; if (currentSlot != null) { tnUICharacterSlot characterSlot = currentSlot.GetComponent <tnUICharacterSlot>(); if (characterSlot != null) { characterSlot.SetAvailable(); } } } m_CurrentSlots[i_TeamIndex] = i_Slot; // Update new selection. { tnUICharacterSlot characterSlot = i_Slot.GetComponent <tnUICharacterSlot>(); if (characterSlot != null) { Color captainColor = m_CaptainsColors[i_TeamIndex]; characterSlot.SetHighlighted(captainColor); } } UpdatePortrait(i_TeamIndex); }
private GameObject GetFirstSlot(int i_TeamIndex) { if (!IsValidIndex(i_TeamIndex)) { return(null); } SlotList slotList = m_LineUp[i_TeamIndex]; if (slotList.Count > 0) { tnUICharacterSlot characterSlot = slotList[0]; if (characterSlot != null) { return(characterSlot.gameObject); } } return(null); }
private tnUICharacterSlot SpawnCharacterSlot() { if (m_CharactersSlotsPool.Count > 0) { tnUICharacterSlot slot = m_CharactersSlotsPool[m_CharactersSlotsPool.Count - 1]; m_CharactersSlotsPool.RemoveAt(m_CharactersSlotsPool.Count - 1); slot.gameObject.SetActive(true); return(slot); } else { if (m_CharacterSlotPrefab == null) { return(null); } tnUICharacterSlot slot = GameObject.Instantiate <tnUICharacterSlot>(m_CharacterSlotPrefab); slot.transform.SetParent(transform, false); return(slot); } }
private GameObject GetSlot(int i_TeamIndex, int i_SlotIndex) { if (!IsValidIndex(i_TeamIndex)) { return(null); } SlotList slotList = m_LineUp[i_TeamIndex]; if (i_SlotIndex < 0 || i_SlotIndex >= slotList.Count) { return(null); } tnUICharacterSlot characterSlot = slotList[i_SlotIndex]; if (characterSlot != null) { return(characterSlot.gameObject); } return(null); }
private void UpdatePortrait(int i_TeamIndex) { if (!IsValidIndex(i_TeamIndex)) { return; } tnCharacterPortrait portrait = m_Portraits[i_TeamIndex]; GameObject currentSelection = m_CurrentSlots[i_TeamIndex]; ClearPortrait(i_TeamIndex); SetPortraitEnable(i_TeamIndex, false); if (portrait != null && currentSelection != null) { tnUICharacterSlot slot = currentSelection.GetComponent <tnUICharacterSlot>(); if (slot != null) { int characterId = slot.characterId; if (characterId != Hash.s_NULL) { tnCharacterData characterData = tnGameData.GetCharacterDataMain(characterId); if (characterData != null) { SetPortraitEnable(i_TeamIndex, true); FacingDir facing = m_Facing[i_TeamIndex]; Sprite characterSprite = (facing == FacingDir.FacingLeft) ? characterData.uiIconFacingLeft : characterData.uiIconFacingRight; portrait.SetCharacterPortrait(characterSprite); portrait.SetName(characterData.displayName); } } } } }
// 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); } } } }
public void Confirm(int i_TeamIndex) { if (IsReady(i_TeamIndex)) { return; } if (IsValidIndex(i_TeamIndex)) { GameObject current = m_CurrentSlots[i_TeamIndex]; if (current != null) { SelectionCache cache = m_SelectionsCache[i_TeamIndex]; GameObject currentSelection = m_CurrentSlots[i_TeamIndex]; if (currentSelection != null) { if (cache.IsEmpty()) { cache.Add(currentSelection); tnUICharacterSlot slot = currentSelection.GetComponent <tnUICharacterSlot>(); if (slot != null) { slot.Select(); } } else { cache.Add(currentSelection); GameObject first = cache[0]; GameObject second = cache[1]; if (first == null || second == null) { return; } tnUICharacterSlot firstSlot = first.GetComponent <tnUICharacterSlot>(); tnUICharacterSlot secondSlot = second.GetComponent <tnUICharacterSlot>(); if (firstSlot == null || secondSlot == null) { return; } if (cache.Count == 2) { Swap(firstSlot, secondSlot); firstSlot.Deselect(); secondSlot.Deselect(); cache.Clear(); } } SfxPlayer.PlayMain(m_ConfirmSfx); } } } }