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); } } }
private void CheckForCancelation(int i_PlayerIndex) { if (!IsValidIndex(i_PlayerIndex)) { return; } IndexList controlledPlayers = m_ControllingMap[i_PlayerIndex]; int controlledPlayerIndex = controlledPlayers.GetLast(); if (!IsValidIndex(controlledPlayerIndex)) { return; } bool cancelPressed = false; PlayerInput playerInput = m_Players[i_PlayerIndex]; if (playerInput != null) { cancelPressed = playerInput.GetButtonDown(s_PlayerInput_Cancel); } else { WiFiPlayerInput wifiPlayerInput = m_WifiPlayers[i_PlayerIndex]; if (wifiPlayerInput != null) { cancelPressed = wifiPlayerInput.GetButtonDown(s_WiFiPlayerInput_Cancel); } } if (cancelPressed) { GameObject currentSelection = m_Selections[controlledPlayerIndex]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetHighlighted(GetPlayerColor(controlledPlayerIndex)); } // Raise event. if (m_OnDeselect != null) { m_OnDeselect.Invoke(); } m_Confirmations[controlledPlayerIndex] = false; } } }
private void PopControllingMap(int i_PlayerIndex) { if (!IsValidIndex(i_PlayerIndex)) { return; } IndexList controlledPlayers = m_ControllingMap[i_PlayerIndex]; if (controlledPlayers.Count <= 1) { return; } { int controlledPlayerIndex = controlledPlayers.GetLast(); GameObject currentSelection = m_Selections[controlledPlayerIndex]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetAvailable(); } } m_Selections[controlledPlayerIndex] = null; } controlledPlayers.Pop(); { int newControlledPlayerIndex = controlledPlayers.GetLast(); if (!IsValidIndex(newControlledPlayerIndex)) { return; } GameObject currentSelection = m_Selections[newControlledPlayerIndex]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetHighlighted(GetPlayerColor(newControlledPlayerIndex)); } } m_Confirmations[newControlledPlayerIndex] = false; } }
private void ClearSlot(int i_SlotIndex) { if (i_SlotIndex < 0 || i_SlotIndex >= m_Slots.Count) { return; } GameObject slotInstance = m_Slots[i_SlotIndex]; tnTeamFlag teamFlag = slotInstance.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetAvailable(); } }
private void Select(int i_TeamIndex, GameObject i_Slot) { if (!IsValidIndex(i_TeamIndex)) { return; } if (i_Slot == null) { return; } // Release previous selection. { GameObject currentSelection = m_Selections[i_TeamIndex]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetAvailable(); } // Raise event. if (m_OnNavigate != null) { m_OnNavigate.Invoke(); } } } m_Selections[i_TeamIndex] = i_Slot; // Update new selection. { tnTeamFlag teamFlag = i_Slot.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetHighlighted(GetPlayerColor(i_TeamIndex)); } } }
public void CancelConfirmedTeam(int i_TeamIndex) { if (IsValidIndex(i_TeamIndex)) { GameObject selection = m_Selections[i_TeamIndex]; if (selection != null) { tnTeamFlag teamSelection = selection.GetComponent <tnTeamFlag>(); if (teamSelection != null) { SfxPlayer.PlayMain(m_CancelSfx); Color color = m_PlayersColors[i_TeamIndex]; teamSelection.SetHighlighted(color); } } } }
private int GetTeamId(int i_PlayerIndex) { if (!IsValidIndex(i_PlayerIndex)) { return(Hash.s_NULL); } GameObject currentSelection = m_Selections[i_PlayerIndex]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { return(teamFlag.teamId); } } return(Hash.s_NULL); // Invalid team. }
public void SetPlayerColor(int i_Index, Color i_Color) { if (i_Index < 0 || i_Index >= s_MaxPlayers) { return; } m_PlayersColors[i_Index] = i_Color; GameObject currentSelection = m_Selections[i_Index]; if (currentSelection != null) { tnTeamFlag teamFlag = currentSelection.GetComponent <tnTeamFlag>(); if (teamFlag != null) { teamFlag.SetColor(i_Color); } } }
// LOGIC public void ClearAll() { for (int index = 0; index < m_Slots.Count; ++index) { GameObject slot = m_Slots[index]; if (slot != null) { tnTeamFlag team = slot.GetComponent <tnTeamFlag>(); if (team != null) { team.Recycle(); } } } m_Slots.Clear(); for (int playerIndex = 0; playerIndex < s_MaxPlayers; ++playerIndex) { m_Selections[playerIndex] = null; } }
// 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); } }