説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ProductCollection.cs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace UnityEngine.Purchasing
  5. {
  6. /// <summary>
  7. /// Provides helper methods to retrieve products by
  8. /// store independent/store specific id.
  9. /// </summary>
  10. public class ProductCollection
  11. {
  12. private Dictionary<string, Product> m_IdToProduct;
  13. private Dictionary<string, Product> m_StoreSpecificIdToProduct;
  14. internal ProductCollection(Product[] products)
  15. {
  16. AddProducts(products);
  17. }
  18. internal void AddProducts(IEnumerable<Product> products)
  19. {
  20. set.UnionWith(products);
  21. all = set.ToArray();
  22. m_IdToProduct = all.ToDictionary(x => x.definition.id);
  23. m_StoreSpecificIdToProduct = all.ToDictionary(x => x.definition.storeSpecificId);
  24. }
  25. /// <summary>
  26. /// The hash set of all products
  27. /// </summary>
  28. public HashSet<Product> set { get; } = new HashSet<Product>();
  29. /// <summary>
  30. /// The array of all products
  31. /// </summary>
  32. public Product[] all { get; private set; }
  33. /// <summary>
  34. /// Gets a product matching an id
  35. /// </summary>
  36. /// <param name="id"> The id of the desired product </param>
  37. /// <returns> The product matching the id, or null if not found </returns>
  38. public Product WithID(string id)
  39. {
  40. m_IdToProduct.TryGetValue(id, out var result);
  41. return result;
  42. }
  43. /// <summary>
  44. /// Gets a product matching a store-specific id
  45. /// </summary>
  46. /// <param name="id"> The store-specific id of the desired product </param>
  47. /// <returns> The product matching the id, or null if not found </returns>
  48. public Product WithStoreSpecificID(string id)
  49. {
  50. Product result = null;
  51. if (id != null)
  52. {
  53. m_StoreSpecificIdToProduct.TryGetValue(id, out result);
  54. }
  55. return result;
  56. }
  57. }
  58. }