NGUIShopIAPItemScript.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using System.Collections;
  3. public class NGUIShopIAPItemScript : MonoBehaviour {
  4. //public float itemCost;//price of the in-app purchase
  5. //public int itemReward;//amount of currency units user will get in return
  6. public Finances.Lots productIdentifier; // IAP product id
  7. private UILabel uilCost;//cost label of the IAP element
  8. private UILabel uilReward;//reward label of the IAP element
  9. //private NGUIMenuScript hNGUIMenuScript;
  10. //private InGameScriptCS hInGameScriptCS;
  11. void Start ()
  12. {
  13. //hNGUIMenuScript = (NGUIMenuScript)GameObject.Find("UI Root (2D)").GetComponent(typeof(NGUIMenuScript));
  14. //hInGameScriptCS = (InGameScriptCS)GameObject.Find("Player").GetComponent(typeof(InGameScriptCS));
  15. /*if (itemCost <= 0)
  16. Debug.Log("EXCEPTION: No cost assigned to the IAP shop element. Check the user documentation.");
  17. else if (itemReward <= 0)
  18. Debug.Log("EXCEPTION: No reward assigned to the IAP shop element. Check the user documentation.");*/
  19. uilCost = (UILabel) transform.Find("Text_Cost").GetComponent(typeof (UILabel));
  20. uilReward = (UILabel) transform.Find("Text_Reward").GetComponent(typeof(UILabel));
  21. /*uilCost.text = "$ " + itemCost.ToString();//display the cost of the item
  22. uilReward.text = itemReward.ToString();//display the virtual currency reward*/
  23. }
  24. void Update()
  25. {
  26. uilCost.text = "$ " + Finances.GetPrice(productIdentifier).ToString();//display the cost of the item
  27. uilReward.text = Finances.GetReward(productIdentifier).ToString();//display the virtual currency reward
  28. }
  29. void OnClick ()
  30. {
  31. #if UNITY_IOS
  32. //StoreKitBinding.purchaseProduct(Finances.GetLotID(productIdentifier), 1);
  33. #endif
  34. //if (StoreKitBinding.canMakePayments())
  35. //{
  36. // StoreKitBinding.purchaseProduct(Finances.GetLotID(productIdentifier), 1);
  37. //}
  38. //give user the bought amount of in-game currency units
  39. //hInGameScriptCS.alterCurrencyCount(itemReward);//award the purcahsed units
  40. //update the currency on the header bar
  41. //hNGUIMenuScript.updateCurrencyOnHeader(hNGUIMenuScript.getCurrentMenu());
  42. }
  43. }