Advertisement
Guest User

Untitled

a guest
Apr 5th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.45 KB | None | 0 0
  1. // (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
  2.  
  3. using UnityEngine;
  4. using System.Collections.Generic;
  5. using Prime31;
  6.  
  7. namespace HutongGames.PlayMaker.Actions
  8. {
  9.     [ActionCategory("StoreKit")]
  10.     [Tooltip("You cannot make any purchases until you have retrieved the products from the server with the requestProductData method")]
  11.     public class RequestProductData : FsmStateAction
  12.     {
  13.         [Tooltip("Array of product ID's from iTunesConnect. MUST match exactly what you have there!")]
  14.         public FsmString[] productIdentifiers;
  15.  
  16.         [UIHint(UIHint.Variable)]
  17.         [Tooltip("Where to store the error if one occurs")]
  18.         public FsmString error;
  19.  
  20.         public FsmEvent onSuccess;
  21.         public FsmEvent onError;
  22.  
  23.         public override void OnEnter()
  24.         {
  25.  
  26.             string[] tempList = new string[productIdentifiers.Length];
  27.             for(var i = 0; i < tempList.Length; ++i) {
  28.                 tempList[i] = productIdentifiers[i].Value;
  29.             }
  30. #if UNITY_IOS
  31.             StoreKitManager.productListRequestFailedEvent += queryInventoryFailedEvent;
  32.             StoreKitHelper.Instance.Start();
  33.             StoreKitBinding.requestProductData( tempList );
  34.  
  35.             StoreKitManager.productListReceivedEvent += allProducts =>
  36.             {
  37.                 Debug.Log( "received total products: " + allProducts.Count );
  38.                 StoreKitHelper.Instance.SetProducts (allProducts);
  39.                 Fsm.Event(onSuccess);
  40.             };
  41.  
  42.  
  43.  
  44. #elif UNITY_ANDROID
  45.             GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
  46.             GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
  47.             GoogleIAB.queryInventory( tempList );
  48. #else
  49.             Finish();
  50. #endif
  51.         }
  52.  
  53.         public override void OnExit() {
  54.  
  55. #if UNITY_IOS
  56.             StoreKitManager.productListRequestFailedEvent -= queryInventoryFailedEvent;
  57. #elif UNITY_ANDROID
  58.             GoogleIABManager.queryInventorySucceededEvent -= queryInventorySucceededEvent;
  59.             GoogleIABManager.queryInventoryFailedEvent -= queryInventoryFailedEvent;
  60. #endif
  61.         }
  62.  
  63. #if UNITY_ANDROID
  64.         void queryInventorySucceededEvent( List<GooglePurchase> purchases, List<GoogleSkuInfo> skus )
  65.         {
  66.             Debug.Log( string.Format( "queryInventorySucceededEvent. total purchases: {0}, total skus: {1}", purchases.Count, skus.Count ) );
  67.             StoreKitHelper.Instance.SetProducts (purchases, skus);
  68.             Fsm.Event(onSuccess);
  69.             Finish();
  70.         }
  71. #endif
  72.  
  73.         void queryInventoryFailedEvent( string inventoryError )
  74.         {
  75.             Debug.LogError( "queryInventoryFailedEvent: " + error );
  76.             error.Value = inventoryError;
  77.             Fsm.Event(onError);
  78.             Finish();
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement