StoreConfiguration.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.Purchasing;
  4. namespace UnityEngine.Purchasing
  5. {
  6. internal class StoreConfiguration
  7. {
  8. public AppStore androidStore { get; private set; }
  9. public StoreConfiguration(AppStore store)
  10. {
  11. androidStore = store;
  12. }
  13. public static string Serialize(StoreConfiguration store)
  14. {
  15. var dic = new Dictionary<string, object>() {
  16. { "androidStore", store.androidStore.ToString() }
  17. };
  18. return MiniJson.JsonEncode(dic);
  19. }
  20. /// <exception cref="System.ArgumentException">Thrown when parsing fails</exception>
  21. public static StoreConfiguration Deserialize(string json)
  22. {
  23. var dic = (Dictionary<string, object>)MiniJson.JsonDecode(json);
  24. AppStore store;
  25. var key = (string)dic["androidStore"];
  26. if (!Enum.IsDefined(typeof(AppStore), key))
  27. store = AppStore.GooglePlay;
  28. else
  29. store = (AppStore)Enum.Parse(typeof(AppStore), (string)dic["androidStore"], true);
  30. return new StoreConfiguration(store);
  31. }
  32. }
  33. }