IAPConfigurationHelper.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #if UNITY_PURCHASING
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Purchasing;
  6. namespace UnityEngine.Purchasing
  7. {
  8. public static class IAPConfigurationHelper
  9. {
  10. /// Populate a ConfigurationBuilder with products from a ProductCatalog
  11. public static void PopulateConfigurationBuilder(ref ConfigurationBuilder builder, ProductCatalog catalog)
  12. {
  13. foreach (var product in catalog.allProducts)
  14. {
  15. IDs ids = null;
  16. if (product.allStoreIDs.Count > 0)
  17. {
  18. ids = new IDs();
  19. foreach (var storeID in product.allStoreIDs)
  20. {
  21. ids.Add(storeID.id, storeID.store);
  22. }
  23. }
  24. #if UNITY_2017_2_OR_NEWER
  25. var payoutDefinitions = new List<PayoutDefinition>();
  26. foreach (var payout in product.Payouts) {
  27. payoutDefinitions.Add(new PayoutDefinition(payout.typeString, payout.subtype, payout.quantity, payout.data));
  28. }
  29. builder.AddProduct(product.id, product.type, ids, payoutDefinitions.ToArray());
  30. #else
  31. builder.AddProduct(product.id, product.type, ids);
  32. #endif
  33. }
  34. }
  35. }
  36. }
  37. #endif