IAPConfigurationHelper.cs 1.3 KB

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