private void RenderListItem(int index, GObject obj) { GButton btn = obj.asButton; btn.title = ""; btn.icon = ""; if (index >= this.goodsList.Count) { return; } Goods goods = this.goodsList[index]; obj.onClick.Clear(); obj.onClick.Add(() => { // 判断包满 if (!GoodsUI.getGoodsDelegate(goods)) { return; } // 移除物品 goodsList.RemoveAt(index); // 通过名字查找实体,调用方法将实体从世界移除 GameObject.Find(goods.name).GetComponent <Goods>().destroy(); // 重置虚拟列表显示数量 goodsGList.numItems = goodsList.Count; if (goodsGList.numItems == 0) { Hide(); } // 刷新列表,物品将向前位移 goodsGList.RefreshVirtualList(); }); btn.title = goods.type; // 判断icon是否为具体路径 string url = goods.icon; if (!url.StartsWith("ui")) { url = UIPackage.GetItemURL("BattleCity8102", "goods-" + goods.icon); } btn.icon = url; // 背景#EFC324表示重要物资,#FFFFFF为普通物资 //btn.GetChild("rightBg").asGraph.color = new Color(); //btn.GetChild("leftBg").asGraph.color = new Color(); btn.GetChild("nameTextField").asTextField.text = goods.goodsName; btn.GetChild("descriptionTextField").asTextField.text = goods.description; btn.GetChild("countTextField").asTextField.text = goods.count + ""; btn.GetChild("coldDownTextField").asTextField.text = goods.coldDownTime + ""; }
private void RenderListItem(int index, GObject obj) { GButton btn = obj.asButton; btn.title = ""; btn.icon = ""; if (index >= box.goodsList.Count) { return; } Goods goods = box.goodsList[index]; btn.title = goods.type; // 判断icon是否为具体路径 string url = goods.icon; if (!url.StartsWith("ui")) { url = UIPackage.GetItemURL("BattleCity8102", "goods-" + goods.icon); } btn.icon = url; // 背景#EFC324表示重要物资,#FFFFFF为普通物资 //btn.GetChild("rightBg").asGraph.color = new Color(); //btn.GetChild("leftBg").asGraph.color = new Color(); btn.GetChild("nameTextField").asTextField.text = goods.goodsName; btn.GetChild("countTextField").asTextField.text = goods.count + ""; btn.GetChild("descriptionTextField").asTextField.text = goods.description; btn.GetChild("coldDownTextField").asTextField.text = goods.coldDownTime + ""; //点击物品拾取,清除上次监听 obj.onClick.Clear(); obj.onClick.Add(() => { // 判断包满 if (!GoodsUI.getGoodsDelegate(goods)) { return; } box.goodsList.RemoveAt(index); boxList.numItems = box.goodsList.Count; boxList.RefreshVirtualList(); }); }