Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
- using UnityEngine;
- using System.Collections.Generic;
- using Prime31;
- namespace HutongGames.PlayMaker.Actions
- {
- [ActionCategory("StoreKit")]
- [Tooltip("You cannot make any purchases until you have retrieved the products from the server with the requestProductData method")]
- public class RequestProductData : FsmStateAction
- {
- [Tooltip("Array of product ID's from iTunesConnect. MUST match exactly what you have there!")]
- public FsmString[] productIdentifiers;
- [UIHint(UIHint.Variable)]
- [Tooltip("Where to store the error if one occurs")]
- public FsmString error;
- public FsmEvent onSuccess;
- public FsmEvent onError;
- public override void OnEnter()
- {
- string[] tempList = new string[productIdentifiers.Length];
- for(var i = 0; i < tempList.Length; ++i) {
- tempList[i] = productIdentifiers[i].Value;
- }
- #if UNITY_IOS
- StoreKitManager.productListRequestFailedEvent += queryInventoryFailedEvent;
- StoreKitHelper.Instance.Start();
- StoreKitBinding.requestProductData( tempList );
- StoreKitManager.productListReceivedEvent += allProducts =>
- {
- Debug.Log( "received total products: " + allProducts.Count );
- StoreKitHelper.Instance.SetProducts (allProducts);
- Fsm.Event(onSuccess);
- };
- #elif UNITY_ANDROID
- GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
- GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
- GoogleIAB.queryInventory( tempList );
- #else
- Finish();
- #endif
- }
- public override void OnExit() {
- #if UNITY_IOS
- StoreKitManager.productListRequestFailedEvent -= queryInventoryFailedEvent;
- #elif UNITY_ANDROID
- GoogleIABManager.queryInventorySucceededEvent -= queryInventorySucceededEvent;
- GoogleIABManager.queryInventoryFailedEvent -= queryInventoryFailedEvent;
- #endif
- }
- #if UNITY_ANDROID
- void queryInventorySucceededEvent( List<GooglePurchase> purchases, List<GoogleSkuInfo> skus )
- {
- Debug.Log( string.Format( "queryInventorySucceededEvent. total purchases: {0}, total skus: {1}", purchases.Count, skus.Count ) );
- StoreKitHelper.Instance.SetProducts (purchases, skus);
- Fsm.Event(onSuccess);
- Finish();
- }
- #endif
- void queryInventoryFailedEvent( string inventoryError )
- {
- Debug.LogError( "queryInventoryFailedEvent: " + error );
- error.Value = inventoryError;
- Fsm.Event(onError);
- Finish();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement