/// <summary> /// 点击-开始合成 /// </summary> public void OnClickForStartSynthesis() { //当前选中的合成道具 ItemsSynthesisBean itemsSynthesis = listSynthesisData[indexSelect]; //检测当前道具是否能合成 bool canSynthesis = itemsSynthesis.CheckSynthesis(); if (!canSynthesis) { //素材不足 无法合成 UIHandler.Instance.ToastHint <ToastView>(TextHandler.Instance.GetTextById(30002)); return; } //首先消耗素材 BaseUIComponent currentUI = UIHandler.Instance.GetOpenUI(); //获取素材 List <ItemsSynthesisMaterialsBean> listMaterials = itemsSynthesis.GetSynthesisMaterials(); UserDataBean userData = GameDataHandler.Instance.manager.GetUserData(); //扣除素材 for (int i = 0; i < listMaterials.Count; i++) { ItemsSynthesisMaterialsBean itemMaterials = listMaterials[i]; for (int f = 0; f < itemMaterials.itemIds.Length; f++) { //只要扣除其中一项素材就行 long itemMaterialId = itemMaterials.itemIds[f]; if (userData.HasEnoughItem(itemMaterialId, itemMaterials.itemNumber)) { userData.RemoveItem(itemMaterialId, itemMaterials.itemNumber); break; } else { continue; } } } //添加道具 itemsSynthesis.GetSynthesisResult(out long itemsId, out int itemNum); int moreNum = userData.AddItems(itemsId, itemNum, null); //如果还有多余的道具 则丢出来 if (moreNum > 0) { Player player = GameHandler.Instance.manager.player; ItemsHandler.Instance.CreateItemCptDrop(itemsId, moreNum, null, player.transform.position + Vector3.up, ItemDropStateEnum.DropNoPick); } UIViewBackpackList backpackUI = currentUI.GetComponentInChildren <UIViewBackpackList>(); backpackUI.RefreshUI(); UIViewShortcuts shortcutsUI = currentUI.GetComponentInChildren <UIViewShortcuts>(); shortcutsUI.RefreshUI(); RefreshUI(); }
public void SetData(ItemsSynthesisBean itemsSynthesis, int index, bool isSelect) { this.index = index; this.itemsSynthesis = itemsSynthesis; itemsSynthesis.GetSynthesisResult(out long resultId, out int resultNum); bool canSynthesis = itemsSynthesis.CheckSynthesis(); SetItemIcon(resultId); SetSynthesisState(canSynthesis); SetSelectState(isSelect); SetPopupInfo(resultId); SetNumber(resultNum, canSynthesis); }