暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IAPConfigurationHelper.cs 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Purchasing;
  5. namespace UnityEngine.Purchasing
  6. {
  7. /// <summary>
  8. /// Helps to set up ConfigurationBuilder.
  9. /// </summary>
  10. public static class IAPConfigurationHelper
  11. {
  12. /// <summary>
  13. /// Populate a ConfigurationBuilder with products from a ProductCatalog
  14. /// </summary>
  15. /// <param name="builder">Will be populated with product identifiers and payouts</param>
  16. /// <param name="catalog">Source of product identifiers and payouts</param>
  17. public static void PopulateConfigurationBuilder(ref ConfigurationBuilder builder, ProductCatalog catalog)
  18. {
  19. foreach (var product in catalog.allValidProducts)
  20. {
  21. IDs ids = null;
  22. if (product.allStoreIDs.Count > 0)
  23. {
  24. ids = new IDs();
  25. foreach (var storeID in product.allStoreIDs)
  26. {
  27. ids.Add(storeID.id, storeID.store);
  28. }
  29. }
  30. #if UNITY_2017_2_OR_NEWER
  31. var payoutDefinitions = new List<PayoutDefinition>();
  32. foreach (var payout in product.Payouts)
  33. {
  34. payoutDefinitions.Add(new PayoutDefinition(payout.typeString, payout.subtype, payout.quantity, payout.data));
  35. }
  36. builder.AddProduct(product.id, product.type, ids, payoutDefinitions.ToArray());
  37. #else
  38. builder.AddProduct(product.id, product.type, ids);
  39. #endif
  40. }
  41. }
  42. }
  43. }