Guest User

Untitled

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