private void SetDetailContent(Commodity data) { if (data != null) { var vip = data.vip_level > 0; if (VIPTag.activeSelf != vip) { VIPTag.SetActive(vip); } if (DetailImage && !DetailImage.gameObject.activeSelf) { DetailImage.gameObject.SetActive(true); } if (DetailBgImage && DetailBgImage.gameObject.activeSelf) { DetailBgImage.gameObject.SetActive(true); } var pic = data.pic; if (DetailImage) { if (!string.IsNullOrEmpty(pic)) { DetailImage.SetTargetPic(pic, ResourcePath.CommodityPath, null, true); } else { DetailImage.Reset(); } } if (DetailBgImage) { var picBg = data.pic_bg; if (!string.IsNullOrEmpty(picBg)) { DetailBgImage.SetTargetPic(picBg, ResourcePath.CommodityPath, null, true); } else { DetailBgImage.Reset(); } } if (DetailName) { if (!DetailName.gameObject.activeSelf) { DetailName.gameObject.SetActive(true); } DetailName.text = data.display_name; } if (DetailPrice) { if (!DetailPrice.gameObject.activeSelf) { DetailPrice.gameObject.SetActive(true); } DetailPrice.SetCurrency(CommodityHelper.GetPrice(data), CommodityHelper.GetCurrencyType(data)); } var bag = _bag.Read(); var user = _user.Read(); var hasCommodity = GameUtil.HasCommodity(bag, data); var equiped = hasCommodity && GameUtil.IsCommodityEquiped(bag, user, data); if (hasCommodity) { // 隐藏购买按钮。 if (BuyBtn && BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(false); } // 使用按钮与是否装备相反。 if (UseBtn) { if (!UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(true); } UseBtn.interactable = !equiped; } if (UnUseBtn) { if (!UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(true); } UnUseBtn.interactable = equiped; } // 6.2版本不再显示典当按钮。 if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } // 6.2版本不再显示典当提示。 if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } else { if (BuyBtn && !BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(true); } if (UseBtn && UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(false); } if (UnUseBtn && UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(false); } if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } } else { if (DetailBgImage) { DetailBgImage.Reset(); } if (DetailImage) { DetailImage.Reset(); } if (DetailName && DetailName.gameObject.activeSelf) { DetailName.gameObject.SetActive(false); } if (DetailPrice && DetailPrice.gameObject.activeSelf) { DetailPrice.gameObject.SetActive(false); } if (BuyBtn && BuyBtn.gameObject.activeSelf) { BuyBtn.gameObject.SetActive(false); } if (UseBtn && UseBtn.gameObject.activeSelf) { UseBtn.gameObject.SetActive(false); } if (UnUseBtn && UnUseBtn.gameObject.activeSelf) { UnUseBtn.gameObject.SetActive(false); } if (SaleBtn && SaleBtn.gameObject.activeSelf) { SaleBtn.gameObject.SetActive(false); } if (SaleTip && SaleTip.gameObject.activeSelf) { SaleTip.gameObject.SetActive(false); } } }
private bool CheckBuyCommodityResult() { var res = _buyCommodityResult.Read(); if (res == null) { return(false); } _dialogManager.ShowWaitingDialog(false); if (res.result == ResultCode.OK) { // 购买成功。 AddCommodity(res.name); // 更新玩家的钱。 var user = _user.Read(); GameUtil.SetMyCurrency(user, CurrencyType.GOLDEN_EGG, res.current_money); GameUtil.SetMyCurrency(user, CurrencyType.YIN_PIAO, res.current_second_money); _user.Invalidate(Time.time); // 播放用钱的声音。 _soundController.PlayUseGoldSound(); _dialogManager.ShowConfirmBox( "恭喜您,成功购买商品^_^", true, "立即使用", () => UseCommodity(res.name, true), false, null, null, true, true, true); // 统计 var commodityList = _commodityList.Read(); var commodity = GameUtil.GetCommodity(commodityList, res.name); if (commodity != null) { var type = CommodityHelper.GetCurrencyType(commodity); var price = CommodityHelper.GetPrice(commodity); var count = DataUtil.CalculateGeValue(type, price); _analyticManager.Buy(res.name, 1, count); } } else { // 购买失败,显示错误信息。 switch (res.result) { case ResultCode.COMMODITY_NOT_FOUND: _dialogManager.ShowToast("购买失败,商品不存在!", 2, true); break; case ResultCode.COMMODITY_BUY_LEVEL_LIMIT: _dialogManager.ShowToast("购买失败,您的等级不够!", 2, true); break; case ResultCode.COMMODITY_BUY_VIP_LIMIT: _dialogManager.ShowToast("购买失败,您的VIP等级不够!", 2, true); break; case ResultCode.COMMODITY_BUY_MONEY_LIMIT: _dialogManager.ShowToast("购买失败,您的钱不够!", 2, true); break; case ResultCode.CURRENCY_NOT_SUPPORTED: _dialogManager.ShowToast("购买失败,商品数据错误!", 2, true); break; // 默认情况下等待服务器端发送的Toast。 } } // 读取过结果之后,就可以清空这个结果了。 _buyCommodityResult.ClearAndInvalidate(Time.time); return(true); }
public override void BindData(int currentIndex, Commodity data) { if (data == null) { return; } _data = data; if (SelectCover && !SelectCover.gameObject.activeSelf) { SelectCover.gameObject.SetActive(false); } var pic = data.pic; if (Image) { if (!string.IsNullOrEmpty(pic)) { Image.SetTargetPic(pic, ResourcePath.CommodityPath, data.pic_url, true); } else { Image.Reset(); } } if (BgImage) { var picBg = data.pic_bg; if (!string.IsNullOrEmpty(picBg)) { BgImage.SetTargetPic(picBg, ResourcePath.CommodityPath, data.pic_bg_url, true); } else { BgImage.Reset(); } } if (data.vip_level > 0) { if (!VIPTag.activeSelf) { VIPTag.SetActive(true); } } else { if (VIPTag.activeSelf) { VIPTag.SetActive(false); } } var bag = _bag.Read(); var user = _user.Read(); if (!GameUtil.HasCommodity(bag, data)) { if (UnlockTag && !UnlockTag.activeSelf) { UnlockTag.SetActive(true); } if (StateGroup && !StateGroup.activeSelf) { StateGroup.SetActive(true); } if (StateText) { StateText.text = "" + CommodityHelper.GetPrice(data) + CurrencyType.LabelOf(CommodityHelper.GetCurrencyType(data)); } } else { if (UnlockTag && UnlockTag.activeSelf) { UnlockTag.SetActive(false); } if (StateGroup && !StateGroup.activeSelf) { StateGroup.SetActive(true); } if (StateText) { StateText.text = GameUtil.IsCommodityEquiped(bag, user, data) ? "<color=#4ae91a>当前装饰</color>" : "<color=#f0aa4b>已购买</color>"; } } }