public void OnSuccessBuy(Merchandise merchandise, ProductInShop productInShop) { if (merchandise.costType == CostType.Pearl) { if (EntireGameManager.getInstance().getPlayerData().pearl < merchandise.cost) { Debug.Log("珍珠不足"); MainUIManager.CreateCheckBox(() => { }, "珍珠不足"); return; } else { EntireGameManager.getInstance().playerData.pearl -= merchandise.cost; } } else { if (EntireGameManager.getInstance().getPlayerData().sugar < merchandise.cost) { MainUIManager.CreateCheckBox(() => { }, "方糖不足"); Debug.Log("方糖不足"); return; } else { EntireGameManager.getInstance().playerData.sugar -= merchandise.cost; } } Debug.Log("成功購買" + merchandise.chineseName); if (merchandise.type == MerchandiseType.Animal) { EntireGameManager.getInstance().getPlayerData().animalList.Add(merchandise.indexName); } else if (merchandise.type == MerchandiseType.Cup) { EntireGameManager.getInstance().getPlayerData().cupList.Add(merchandise.indexName); } else if (merchandise.type == MerchandiseType.Liquid) { EntireGameManager.getInstance().getPlayerData().liquidList.Add(merchandise.indexName); } productInShop.HaveProduct(true); EntireGameManager.getInstance().Save(); AudioManager.Play("purchase"); UpdateMoney(); }
void AddProduct(Merchandise product, MerchandiseType type, int index) { if (type == MerchandiseType.Animal) { RectTransform rect = Instantiate(AnimalProductPrefab, animalShop).GetComponent <RectTransform>(); float x = index * itemWidth; rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y); ProductInShop prod = rect.GetComponent <ProductInShop>(); prod.icon.sprite = product.SelectViewSprite; prod.nameText.text = product.chineseName; prod.costText.text = "x" + product.cost; prod.SetCostType(product.costType); if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName)) { prod.HaveProduct(true); } else { prod.HaveProduct(false); } prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod)); } else if (type == MerchandiseType.Cup) { RectTransform rect = Instantiate(CupProductPrefab, cupShop).GetComponent <RectTransform>(); float x = index * itemWidth; rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y); ProductInShop prod = rect.GetComponent <ProductInShop>(); prod.icon.sprite = product.SelectViewSprite; prod.nameText.text = product.chineseName; prod.costText.text = "x" + product.cost; prod.SetCostType(product.costType); if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName)) { prod.HaveProduct(true); } else { prod.HaveProduct(false); } prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod)); } else if (type == MerchandiseType.Liquid) { RectTransform rect = Instantiate(LiquidProductPrefab, liquidShop).GetComponent <RectTransform>(); float x = index * itemWidth; rect.anchoredPosition = new Vector2(x, rect.anchoredPosition.y); ProductInShop prod = rect.GetComponent <ProductInShop>(); prod.nameText.text = product.chineseName; prod.costText.text = "x" + product.cost; prod.SetCostType(product.costType); if (EntireGameManager.getInstance().getPlayerData().HaveItem(type, product.indexName)) { prod.HaveProduct(true); } else { prod.HaveProduct(false); } prod.Cover.gameObject.GetComponent <Button>().onClick.AddListener(() => OnBuyClicked(product, prod)); } }