설명 없음
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.

PurchasingFactory.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine.Purchasing.Extension;
  5. namespace UnityEngine.Purchasing
  6. {
  7. /// <summary>
  8. /// Manages instantiation of specific store services based on provided <c>IPurchasingModule</c>s.
  9. /// </summary>
  10. internal class PurchasingFactory : IPurchasingBinder, IExtensionProvider
  11. {
  12. private readonly Dictionary<Type, IStoreConfiguration> m_ConfigMap = new Dictionary<Type, IStoreConfiguration>();
  13. private readonly Dictionary<Type, IStoreExtension> m_ExtensionMap = new Dictionary<Type, IStoreExtension>();
  14. private IStore m_Store;
  15. private ICatalogProvider m_CatalogProvider;
  16. public PurchasingFactory(IPurchasingModule first, params IPurchasingModule[] remainingModules)
  17. {
  18. first.Configure(this);
  19. foreach (var module in remainingModules)
  20. {
  21. module.Configure(this);
  22. }
  23. }
  24. public string storeName { get; private set; }
  25. public IStore service
  26. {
  27. get
  28. {
  29. if (m_Store != null)
  30. {
  31. return m_Store;
  32. }
  33. throw new InvalidOperationException("No impl available!");
  34. }
  35. set => m_Store = value;
  36. }
  37. public void RegisterStore(string name, IStore s)
  38. {
  39. // We use the first store that supports our current
  40. // platform.
  41. if (m_Store == null && s != null)
  42. {
  43. storeName = name;
  44. service = s;
  45. }
  46. }
  47. public void RegisterExtension<T>(T instance) where T : IStoreExtension
  48. {
  49. m_ExtensionMap[typeof(T)] = instance;
  50. }
  51. public void RegisterConfiguration<T>(T instance) where T : IStoreConfiguration
  52. {
  53. m_ConfigMap[typeof(T)] = instance;
  54. }
  55. /// <summary>
  56. /// Get the specified <c>IStoreConfiguration</c>.
  57. ///
  58. /// If the store implements the requested interface,
  59. /// it will be returned.
  60. /// </summary>
  61. public T GetConfig<T>() where T : IStoreConfiguration
  62. {
  63. if (service is T)
  64. {
  65. return (T)service;
  66. }
  67. var type = typeof(T);
  68. if (m_ConfigMap.ContainsKey(type))
  69. {
  70. return (T)m_ConfigMap[type];
  71. }
  72. throw new ArgumentException("No binding for config type " + type);
  73. }
  74. /// Get the specified <c>IStoreExtension</c>.
  75. ///
  76. /// If the store implements the requested interface,
  77. /// it will be returned.
  78. public T GetExtension<T>() where T : IStoreExtension
  79. {
  80. if (service is T)
  81. {
  82. return (T)service;
  83. }
  84. var t = typeof(T);
  85. if (m_ExtensionMap.ContainsKey(t))
  86. {
  87. return (T)m_ExtensionMap[t];
  88. }
  89. throw new ArgumentException("No binding for type " + t);
  90. }
  91. public void SetCatalogProvider(ICatalogProvider provider)
  92. {
  93. m_CatalogProvider = provider;
  94. }
  95. public void SetCatalogProviderFunction(Action<Action<HashSet<ProductDefinition>>> func)
  96. {
  97. m_CatalogProvider = new SimpleCatalogProvider(func);
  98. }
  99. internal ICatalogProvider GetCatalogProvider()
  100. {
  101. return m_CatalogProvider;
  102. }
  103. }
  104. }