protected override LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0 || index >= DataManger.TotalItemCount) { return(null); } GridItemData itemData = DataManger.GetItemDataByIndex(index); if (itemData == null) { return(null); } LoopListViewItem2 item = listView.NewListViewItem(ItemName); EquipItem itemScript = item.GetComponent <EquipItem>(); itemScript.Init(); itemScript.SetData(index, UnityEngine.Random.Range(1, 6), SpriteArray[UnityEngine.Random.Range(0, SpriteArray.Length)].name, UnityEngine.Random.Range(0, 2) == 1, UnityEngine.Random.Range(1, 1000), UnityEngine.Random.Range(1, 6)); itemScript.GetComponent <Button>().onClick.RemoveAllListeners(); itemScript.GetComponent <Button>().onClick.AddListener(delegate { Debug.Log(itemScript.Index); }); return(item); }
protected override LoopListViewItem2 OnGetItemByIndex(LoopListView2 listView, int index) { if (index < 0 || index >= DataManger.TotalItemCount) { return(null); } GridItemData itemData = DataManger.GetItemDataByIndex(index); if (itemData == null) { return(null); } LoopListViewItem2 item = listView.NewListViewItem(ItemName); for (int i = 0; i < row; i++) { int itemIndex = index * row + i; EquipItem itemScript = item.transform.GetChild(i).GetComponent <EquipItem>(); if (itemIndex >= DataManger.TotalDataCount) { itemScript.gameObject.SetActive(false); continue; } else { itemScript.gameObject.SetActive(true); } itemScript.Init(); itemScript.SetData(itemIndex, UnityEngine.Random.Range(1, 6), SpriteArray[UnityEngine.Random.Range(0, SpriteArray.Length)].name, UnityEngine.Random.Range(0, 2) == 1, UnityEngine.Random.Range(1, 1000), UnityEngine.Random.Range(1, 6)); itemScript.GetComponent <Button>().onClick.RemoveAllListeners(); itemScript.GetComponent <Button>().onClick.AddListener(delegate { Debug.Log(itemScript.Index); }); } return(item); }