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

CurrentAppSimulator.cs 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Xml.Linq;
  6. using Windows.ApplicationModel.Store;
  7. using Windows.Foundation;
  8. using Windows.Storage;
  9. namespace UnityEngine.Purchasing.Default
  10. {
  11. class UnibillCurrentAppSimulator : ICurrentApp
  12. {
  13. public void BuildMockProducts(List<WinProductDescription> winProducts)
  14. {
  15. StorageFolder myfolder = ApplicationData.Current.LocalFolder;
  16. if (!Exists("WindowsStoreProxy.xml"))
  17. {
  18. myfolder.CreateFileAsync("WindowsStoreProxy.xml").AsTask().Wait();
  19. }
  20. var file = myfolder.GetFileAsync("WindowsStoreProxy.xml").AsTask().Result;
  21. FileIO.WriteTextAsync(file, BuildDoc(winProducts).ToString()).AsTask().Wait();
  22. var task = CurrentAppSimulator.ReloadSimulatorAsync(file).AsTask();
  23. task.Wait();
  24. }
  25. private bool Exists(string fileName)
  26. {
  27. try
  28. {
  29. var task = ApplicationData.Current.LocalFolder.GetFileAsync(fileName).AsTask();
  30. task.Wait();
  31. if (task.Exception == null)
  32. {
  33. return true;
  34. }
  35. }
  36. catch
  37. {
  38. // Filenotfound
  39. }
  40. return false;
  41. }
  42. private XDocument BuildDoc(List<WinProductDescription> winProducts)
  43. {
  44. XNamespace xml = "xml";
  45. XElement CurrentApp =
  46. new XElement("CurrentApp",
  47. new XElement("ListingInformation",
  48. new XElement("App",
  49. new XElement("AppId", "2B14D306-D8F8-4066-A45B-0FB3464C67F2"),
  50. new XElement("LinkUri", "http://apps.windows.microsoft.com/app/2B14D306-D8F8-4066-A45B-0FB3464C67F2"),
  51. new XElement("CurrentMarket", "en-US"),
  52. new XElement("AgeRating", "3"),
  53. new XElement("MarketData", new XAttribute(XNamespace.Xml + "lang", "en-us"),
  54. new XElement("Name", "Unity IAP demo full license"),
  55. new XElement("Description", "Unity IAP Mock mode"),
  56. new XElement("Price", "4.99"),
  57. new XElement("CurrencySymbol", "$")
  58. )
  59. ),
  60. winProducts.Select(x => new XElement("Product", new XAttribute("ProductId", x.platformSpecificID), new XAttribute("ProductType", x.consumable ? "Consumable" : "Durable"),
  61. new XElement("MarketData", new XAttribute(XNamespace.Xml + "lang", "en-us"),
  62. new XElement("Name", x.title),
  63. new XElement("Price", 0.01m),
  64. new XElement("CurrencySymbol", RegionInfo.CurrentRegion.CurrencySymbol)
  65. )
  66. )
  67. )
  68. ),
  69. new XElement("LicenseInformation",
  70. new XElement("App",
  71. new XElement("IsActive", "true"),
  72. new XElement("IsTrial", "false")
  73. )
  74. )
  75. );
  76. var doc = new XDocument();
  77. doc.Add(CurrentApp);
  78. return doc;
  79. }
  80. public IAsyncOperation<IReadOnlyList<UnfulfilledConsumable>> GetUnfulfilledConsumablesAsync()
  81. {
  82. return CurrentAppSimulator.GetUnfulfilledConsumablesAsync();
  83. }
  84. public IAsyncOperation<ListingInformation> LoadListingInformationAsync()
  85. {
  86. return CurrentAppSimulator.LoadListingInformationAsync();
  87. }
  88. public IAsyncOperation<FulfillmentResult> ReportConsumableFulfillmentAsync(string productId, Guid transactionId)
  89. {
  90. return CurrentAppSimulator.ReportConsumableFulfillmentAsync(productId, transactionId);
  91. }
  92. public IAsyncOperation<PurchaseResults> RequestProductPurchaseAsync(string productId)
  93. {
  94. return CurrentAppSimulator.RequestProductPurchaseAsync(productId);
  95. }
  96. public IAsyncOperation<string> RequestProductReceiptAsync(string productId)
  97. {
  98. return CurrentAppSimulator.GetProductReceiptAsync(productId);
  99. }
  100. public LicenseInformation LicenseInformation
  101. {
  102. get
  103. {
  104. return CurrentAppSimulator.LicenseInformation;
  105. }
  106. }
  107. public IAsyncOperation<string> RequestAppReceiptAsync()
  108. {
  109. return CurrentAppSimulator.GetAppReceiptAsync();
  110. }
  111. }
  112. }