/// <summary> /// 更新用于展示的商品列表 /// </summary> public void UpdateShowCommdities(CommditType commidtyType) { showItemGrids = storeLogic.FindItemsWithCommidtyType(commidtyType); int i = 0; for (; i < showItemGrids.Count; i++) { ItemGrid itemGrid = showItemGrids[i]; itemGrid.index = i; itemGrid.CanBuy = storeLogic.IsCanBuyItem(itemGrid, heroMono); // 如果当前ItemPanelView够用就用之前的创建的 // 当不够用的时候,创建新的ItemPanelView if (i >= itemGridsView.Count) { CreateItemPanel(itemGrid); } itemGridsView[i].Reveal(); } for (; i < itemGridsView.Count; i++) { itemGridsView[i].Hide(); } }
/// <summary> /// 绑定按钮的事件(即分类按钮,展开和收起商店按钮) /// </summary> private void BindButtonEvent() { // 绑定分类按钮的Click事件 for (int i = 0; i < categoryButtons.Count(); i++) { CommditType type = (CommditType)i; Button button = categoryButtons[i]; button.onClick.AddListener(() => { showCommidtyType = type; UpdateShowCommdities(showCommidtyType); UpdateButtonForcus(button); }); } // 绑定展开/收起商店按钮事件 OnOrOffButton.onClick.AddListener(() => { if (canvasGroup.alpha == 1) { // 商店处于开启状态,点击按钮进行收缩 Hide(); OnOrOffButtonText.text = "<<< 展开商店"; } else if (canvasGroup.alpha == 0) { // 商店处于关闭状态,点击按钮进行展开 Reveal(); OnOrOffButtonText.text = "收起 >>>"; } }); }
public List <ItemGrid> FindItemsWithCommidtyType(CommditType commditType, int itemLevel = 0) { List <ItemGrid> itemGrids = new List <ItemGrid>(); switch (commditType) { case CommditType.Weapon: // 武器 case CommditType.Armor: // 防具 case CommditType.Consumable: // 消耗品 case CommditType.Decorative: // 装饰品 case CommditType.Other: // 其他道具 return(soldProps.FindAll((ItemGrid itemGrid) => { if (itemGrid.item != null) { return itemGrid.item.commditType == commditType || commditType == CommditType.All; } return false; })); default: return(soldProps); } }