public void GenerateItems(int from, int to, bool append = false, bool newDataAvailable = false) { to = Mathf.Clamp(to, 1, m_Data.Length); if (to == items.Count && !newDataAvailable) { //update exising items for (int i = 0; i < items.Count; i++) { ScrollListItem scrollListItem = items[i].GetComponent <ScrollListItem>(); scrollListItem.data = m_Data[i]; } return; } if (items.Count > 0 && !append) { DestroyItems(); } if (m_Data != null && m_Data.Length > 0) { for (int i = from; i < to; i++) { SDKJob job = m_Data[i]; GameObject item = Instantiate(itemTemplate); items.Add(item); item.name = item.name + "_" + i; item.SetActive(true); item.transform.SetParent(contentParent, false); ScrollListItem scrollListItem = item.GetComponent <ScrollListItem>(); scrollListItem.PopulateData(job, IsActive(job.id)); } } if (newDataAvailable) { ScrollToTop(); } loadMoreButton.SetActive(m_Data.Length > to); loadMoreButton.transform.SetAsLastSibling(); }
public void GenerateItems() { int newDataLen = m_Data == null ? 0 : m_Data.Length; bool scroll = items.Count != newDataLen; if (!scroll) { for (int i = 0; i < items.Count; i++) { ScrollListItem scrollListItem = items[i].GetComponent <ScrollListItem>(); scrollListItem.data = m_Data[i]; } return; } if (items.Count > 0) { DestroyItems(); } if (m_Data != null && m_Data.Length > 0) { for (int i = 0; i < m_Data.Length; i++) { SDKJob job = m_Data[i]; GameObject item = Instantiate(itemTemplate); items.Add(item); item.SetActive(true); item.transform.SetParent(contentParent, false); ScrollListItem scrollListItem = item.GetComponent <ScrollListItem>(); scrollListItem.PopulateData(job, IsActive(job.id)); } } if (scroll) { ScrollToTop(); } }