void OnClick() { /* * GameObject mallTableObj = GameObject.Find("MallDragPanel"); * //MallInitialization tableCom = mallTableObj.GetComponent<MallInitialization>(); * //tableCom.addDiamond("com.mfp.frozen.cash_30"); * mallTableObj.SendMessage("addDiamond", "com.mfp.frozen.cash_30"); * * return; */ GameObject diamondCellObj = transform.parent.gameObject; DiamondCell diamondCellCom = diamondCellObj.GetComponent <DiamondCell>(); int productID = diamondCellCom.diamondProductID; Debug.Log("Press item cell" + productID); bool purchaseSuccess = ItemModel.Instance.buyItem(productID); if (purchaseSuccess) { Debug.Log("Purchase Success!"); PopupMessage.Show(Language.Get("PURCHASE_ITEM_SUCCESS")); packageTableCom.UpdateContent(); } else { Debug.Log("Not enough diamond. Then jump to mall tab."); PopupMessage.Show(Language.Get("NOT_ENOUGH_DIAMOND")); MallTab mallTab = GameObject.Find("MallTabButton2").gameObject.GetComponent <MallTab>(); mallTab.OnClick(); } }
/** * diamondProductID return 0,1,2,3 * paynum: 1,2,3,4 * 1 2元 20钻 * 2 6元 65钻 * 3 10元 110钻 * 4 15元 170钻 */ public void OnClick() { Transform parentTrans = transform.parent; GameObject diamondCellObj = parentTrans.gameObject; DiamondCell diamondCellCom = diamondCellObj.GetComponent <DiamondCell>(); int diamondProductID = diamondCellCom.diamondProductID; #if UNITY_ANDROID int paynum = diamondProductID + 1; MFPBillingAndroid.Instance.pay(paynum.ToString()); #elif UNITY_IPHONE if (purchasing) { return; } purchasing = true; DiamondProductData diamondProduct = ItemModel.Instance.diamondProducts[diamondProductID]; Debug.Log("purchase ProductID:" + diamondProductID); InAppPurchasesSystem.OnPurchaseSuccess += OnPurchaseSuccess; InAppPurchasesSystem.OnPurchaseFail += OnPurchaseFail; InAppPurchasesSystem.OnPurchaseCancel += OnPurchaseFail; InAppPurchasesSystem.Instance.PurchaseProduct((InAppPurchasesSystem.InAppPurchase)diamondProductID); #endif Debug.Log("Click diamond " + diamondProductID); }
// Use this for initialization void Start() { // Update content List <ItemProductData> itemProducts = ItemModel.Instance.itemProducts; for (int i = 0; i < this.transform.childCount; i++) { ItemProductData productData = itemProducts[i]; ItemData itemData = ItemModel.Instance.itemDataDict[productData.itemName]; GameObject cellObj = transform.GetChild(i).gameObject; DiamondCell cellCom = cellObj.GetComponent <DiamondCell>(); cellCom.diamondProductID = i; // item name GameObject nameLabelObj = cellCom.transform.Find("NameLabel").gameObject; UILabel nameLabelCom = nameLabelObj.GetComponent <UILabel>(); nameLabelCom.text = Language.Get(itemData.textKey); // itemData.name; // item sprite GameObject itemSpriteObj = cellCom.transform.Find("ItemSprite").gameObject; UISprite itemSpriteCom = itemSpriteObj.GetComponent <UISprite>(); itemSpriteCom.spriteName = itemData.spriteName; if (productData.itemName == ItemModel.MAGIC_POWER) { itemSpriteObj.transform.localScale = new Vector3(62, 100, 0); } // item introduction GameObject introLabelObj = cellCom.transform.Find("IntroLabel").gameObject; UILabel introLabelCom = introLabelObj.GetComponent <UILabel>(); introLabelCom.text = Language.Get(itemData.descKey); // item number GameObject itemNumObj = cellCom.transform.Find("ItemNumLabel").gameObject; UILabel itemNumCom = itemNumObj.GetComponent <UILabel>(); itemNumCom.text = productData.itemNum.ToString(); itemNumCom.transform.localScale = new Vector3(40, 40, 0); itemNumCom.transform.localPosition = new Vector3(40, -30, 0); // diamond number GameObject diamondNumObj = cellCom.transform.Find("ConfirmButton/NumLabel").gameObject; UILabel diamondNumCom = diamondNumObj.GetComponent <UILabel>(); diamondNumCom.text = productData.diamondNum.ToString(); } }
// Use this for initialization void Start() { for (int i = 0; i < transform.childCount; i++) { DiamondCell cellCom = transform.GetChild(i).gameObject.GetComponent <DiamondCell>(); cellCom.diamondProductID = i; DiamondProductData diamondProduct = ItemModel.Instance.diamondProducts[i]; // item name GameObject nameLabelObj = cellCom.transform.Find("NameLabel").gameObject; UILabel nameLabelCom = nameLabelObj.GetComponent <UILabel>(); nameLabelCom.text = Language.Get(diamondProduct.name + "_NAME"); // itemData.name; // item sprite GameObject itemSpriteObj = cellCom.transform.Find("ItemSprite").gameObject; UISprite itemSpriteCom = itemSpriteObj.GetComponent <UISprite>(); itemSpriteCom.spriteName = diamondProduct.name + "_PIC"; // item introduction GameObject introLabelObj = cellCom.transform.Find("IntroLabel").gameObject; UILabel introLabelCom = introLabelObj.GetComponent <UILabel>(); #if UNITY_IPHONE introLabelCom.text = Language.Get(diamondProduct.name + "_DESC_IOS"); #else introLabelCom.text = Language.Get(diamondProduct.name + "_DESC"); #endif // RMB number GameObject diamondNumObj = cellCom.transform.Find("ConfirmButton/NumLabel").gameObject; UILabel diamondNumCom = diamondNumObj.GetComponent <UILabel>(); if (diamondProduct.displayPrice == "") { // Debug.Log("productID: " + diamondProduct.productID + " has no localPrice"); diamondNumCom.text = diamondProduct.price + Language.Get("CHINESE_YUAN"); } else { // Debug.Log("productID: " + diamondProduct.productID + " has localPrice: " + diamondProduct.displayPrice); diamondNumCom.text = diamondProduct.displayPrice; } } }
public void UpdateContent() { Debug.Log("DiamondTable update content!"); for (int i = 0; i < transform.childCount; i++) { DiamondCell cellCom = transform.GetChild(i).gameObject.GetComponent <DiamondCell>(); cellCom.diamondProductID = i; DiamondProductData diamondProduct = ItemModel.Instance.diamondProducts[i]; Debug.Log("productID:" + diamondProduct.productID); InAppProduct product = InAppPurchasesSystem.Instance.GetProduct(diamondProduct.productID); if (product != null) { // RMB number Debug.Log("text: " + product.currencyCode.ToString() + " " + product.price.ToString()); GameObject diamondNumObj = cellCom.transform.Find("ConfirmButton/NumLabel").gameObject; UILabel diamondNumCom = diamondNumObj.GetComponent <UILabel>(); diamondNumCom.text = product.currencyCode.ToString() + " " + product.price.ToString(); } } }
public void UpdateContent() { List <string> itemNames = new List <string>(); List <int> itemNums = new List <int>(); if (UserManagerCloud.Instance.CurrentUser.IcePick > 0) { itemNames.Add(ItemModel.ICE_PICK); itemNums.Add(UserManagerCloud.Instance.CurrentUser.IcePick); } if (UserManagerCloud.Instance.CurrentUser.MagicPower > 0) { itemNames.Add(ItemModel.MAGIC_POWER); itemNums.Add(UserManagerCloud.Instance.CurrentUser.MagicPower); } if (UserManagerCloud.Instance.CurrentUser.SnowBall > 0) { itemNames.Add(ItemModel.SNOW_BALL); itemNums.Add(UserManagerCloud.Instance.CurrentUser.SnowBall); } if (UserManagerCloud.Instance.CurrentUser.Hourglass > 0) { itemNames.Add(ItemModel.HOUR_GLASS); itemNums.Add(UserManagerCloud.Instance.CurrentUser.Hourglass); } for (int i = 0; i < itemNames.Count; i++) { string itenName = itemNames[i]; int itemNum = itemNums[i]; ItemData itemData = ItemModel.Instance.itemDataDict[itenName]; GameObject cellObj = transform.GetChild(i).gameObject; DiamondCell cellCom = cellObj.GetComponent <DiamondCell>(); // item name GameObject nameLabelObj = cellCom.transform.Find("NameLabel").gameObject; UILabel nameLabelCom = nameLabelObj.GetComponent <UILabel>(); nameLabelCom.text = Language.Get(itemData.textKey); // item sprite GameObject itemSpriteObj = cellCom.transform.Find("ItemSprite").gameObject; UISprite itemSpriteCom = itemSpriteObj.GetComponent <UISprite>(); itemSpriteCom.spriteName = itemData.spriteName; if (itemData.name == ItemModel.MAGIC_POWER) { itemSpriteObj.transform.localScale = new Vector3(62, 100, 0); } // item introduction GameObject introLabelObj = cellCom.transform.Find("IntroLabel").gameObject; UILabel introLabelCom = introLabelObj.GetComponent <UILabel>(); introLabelCom.text = Language.Get(itemData.descKey); // item number GameObject itemNumObj = cellCom.transform.Find("ItemNumLabel").gameObject; UILabel itemNumCom = itemNumObj.GetComponent <UILabel>(); itemNumCom.text = itemNum.ToString(); itemNumCom.transform.localScale = new Vector3(40, 40, 0); itemNumCom.transform.localPosition = new Vector3(40, -30, 0); packageCells[i].SetActive(true); } for (int i = itemNames.Count; i < packageCells.Count; i++) { packageCells[i].SetActive(false); } // Re-position UIGrid gridCom = this.GetComponent <UIGrid>(); gridCom.Reposition(); }