Advertisement
Guest User

Untitled

a guest
May 11th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections.Generic;
  3. using Prime31;
  4.  
  5. namespace HutongGames.PlayMaker.Actions
  6. {
  7.     [ActionCategory("Gets the price of a In App Purchase")]
  8.     [Tooltip("Get Price")]
  9.     public class GetPrice : FsmStateAction
  10.     {  
  11.         [RequiredField]
  12.         [Tooltip("product ID from iTunesConnect. MUST match exactly what you have there!")]
  13.         public FsmString identifier;
  14.  
  15.         [RequiredField]
  16.         [Tooltip("Where to store the price, it is a string containg the currency symbol as well. Example $1.99")]
  17.         public FsmString price;
  18.         public override void OnEnter()
  19.         {
  20. #if UNITY_IOS || UNITY_ANDROID
  21.  
  22.             price.Value = GetProductPrice(identifier.Value);
  23. #endif
  24.  
  25.             Finish();
  26.  
  27.         }
  28.  
  29.         #if UNITY_IOS
  30.         public string GetProductPrice(string identifier) {
  31.  
  32.             var products = StoreKitHelper.Instance.GetProducts();
  33.             for(var i = 0; i < products.Count; ++i) {
  34.                 if(products[i].productIdentifier == identifier)
  35.                     return products[i].price;
  36.             }
  37.  
  38.             return "Error. Product not found";
  39.         }
  40.         #elif UNITY_ANDROID
  41.         public string GetProductPrice(string identifier) {
  42.            
  43.             var products = StoreKitHelper.Instance.GetSkus();
  44.             for(var i = 0; i < products.Count; ++i) {
  45.                 if(products[i].productId == identifier)
  46.                     return products[i].price;
  47.             }
  48.            
  49.             return "Error. Product not found";
  50.         }
  51.         #endif
  52.  
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement