private void CollectElements() { m_elementList.Clear(); m_staticElementList.Clear(); m_dynamicElementList.Clear(); for (int i = 0; i < transform.childCount; i++) { Transform child = rectTransform.GetChild(i); if (!child.gameObject.activeInHierarchy) { continue; } UILayoutGroupElement element = child.GetComponent <UILayoutGroupElement>(); if (element == null) { continue; } m_elementList.Add(element); UILayoutGroupElementStatic staticElement = element as UILayoutGroupElementStatic; if (staticElement != null) { m_staticElementList.Add(staticElement); } UILayoutGroupElementDynamic dynamicElement = element as UILayoutGroupElementDynamic; if (dynamicElement != null) { m_dynamicElementList.Add(dynamicElement); } } }
public T GetLayoutGroupItem <T>(int prefabIndex = 0) where T : UILayoutGroupItem { T item = DrawOutFromList <T>(m_releasedItemList, prefabIndex); if (item == null) { item = DrawOutFromList <T>(m_spareItemList, prefabIndex); } if (item == null) { UILayoutGroupElementDynamic prefab = GetDynamicPrefab(prefabIndex); if (prefab == null) { return(null); } if (!prefab.gameObject.activeSelf) { prefab.gameObject.SetActive(true); m_needPrefabHide = true; } GameObject go = Instantiate(prefab.gameObject, m_layoutGroup.transform); UILayoutGroupElementDynamic element = go.GetComponent <UILayoutGroupElementDynamic>(); element.prefabIndex = prefabIndex; ItemInitializer itemInitializer; if (m_itemInitializerMap.TryGetValue(typeof(T), out itemInitializer)) { item = itemInitializer.Initialize(go) as T; item.InitElement(); } } m_usingItemList.Add(item); return(item); }
private void HideAllPrefab() { for (int i = 0; i < m_dynamicPrefabList.Count; ++i) { UILayoutGroupElementDynamic prefab = m_dynamicPrefabList[i]; if (prefab != null && prefab.gameObject.activeSelf) { prefab.gameObject.SetActive(false); } } }
private void RefreshDynamicElements(int indexCursor) { for (int i = 0; i < m_dynamicElementList.Count; ++i) { UILayoutGroupElementDynamic dynamicElement = m_dynamicElementList[i]; indexCursor = GetUnUsedIndex(indexCursor); int index = indexCursor; indexCursor++; dynamicElement.index = index; RecordIndex(index); } }
public void InitElement() { m_element = GetComponent <UILayoutGroupElementDynamic>(); }