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); } } }
// 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); } }