private void Select(int id, ScrollListItem listItem) { selectedId = id; moveScrollToTransform = listItem.transform; OnListItemSelect?.Invoke(id, listItem); UpdateNavigation(); leftList?.UpdateNavigation(); rightList?.UpdateNavigation(); }
public void Draw(int count, int?selectDefaultId = null) { ScrollListItem item; for (int i = count; i < listParent.childCount; i++) { listParent.GetChild(i).gameObject.SetActive(false); } items.Clear(); if (count > 0) { for (int i = 0; i < count; i++) { if (i >= listParent.childCount) { item = Instantiate(itemPrefab, listParent); } else { item = listParent.GetChild(i).GetComponent <ScrollListItem>(); } items.Add(item); item.gameObject.SetActive(true); OnListItemCreate(i, item); if (selectDefaultId != null && selectDefaultId == i) { item.Select(); Select(i, item); } int id = i; ScrollListItem listItemLocal = item; item.selectEntry.callback.RemoveAllListeners(); item.selectEntry.callback.AddListener(delegate { Select(id, listItemLocal); }); item.pointerEntry.callback.RemoveAllListeners(); item.pointerEntry.callback.AddListener(delegate { listItemLocal.Select(); }); } } }
private void Awake() { itemPrefab = listParent.GetChild(0).GetComponent <ScrollListItem>(); scrollRect = GetComponent <ScrollRect>(); }