/// <summary> /// 点击商店道具界面 /// </summary> public void onClickPropScrollView() { propScrollView.gameObject.SetActive(true); goldScrollView.gameObject.SetActive(false); for (int i = 0; i < shopContent.transform.childCount; i++) { GameObject go = shopContent.transform.GetChild(i).gameObject; Destroy(go); } List <PrototypeData> shopProtoList = PrototypeManager.Instance.GetDataListByType("ShopPrototype"); for (int j = 0; j < shopProtoList.Count; j++) { GameObject shopItem = (GameObject)Instantiate(propItem); ShopPrototype shopData = shopProtoList[j] as ShopPrototype; GameDebug.Log("-----商店=" + shopData.Name); shopItem.transform.parent = shopContent.transform; shopItem.transform.localScale = new Vector3(1, 1, 1); Text xianjia = shopItem.transform.FindChild("xianjia").GetComponent <Text>(); xianjia.text = shopData.Price.ToString(); Text yuanjia = shopItem.transform.FindChild("yuanjia").GetComponent <Text>(); yuanjia.text = shopData.OriginalPrice.ToString(); Image icon = shopItem.transform.FindChild("icon").GetComponent <Image>(); icon.sprite = propIconSprite[shopData.Icon - 1]; Text num = shopItem.transform.FindChild("num").GetComponent <Text>(); num.text = shopData.Num.ToString(); Text saleNum = shopItem.transform.FindChild("saleNum").GetComponent <Text>(); saleNum.text = shopData.Sale.ToString(); Button shopButton = shopItem.GetComponent <Button>(); shopButton.onClick.AddListener(() => onShopClick(shopData)); } }
void onShopClick(ShopPrototype data) { GameDebug.Log("-----商店=" + data.Name); }