PromoMetadata.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. namespace UnityEngine.Monetization
  5. {
  6. public struct PromoItem
  7. {
  8. public string productId;
  9. public decimal quantity;
  10. public string itemType;
  11. }
  12. public struct PromoMetadata
  13. {
  14. public DateTime impressionDate;
  15. public TimeSpan offerDuration;
  16. public Product premiumProduct;
  17. public PromoItem[] costs;
  18. public PromoItem[] payouts;
  19. public IDictionary<string, object> customInfo;
  20. public bool isPremium => premiumProduct.productId != null;
  21. public TimeSpan timeRemaining
  22. {
  23. get
  24. {
  25. if (impressionDate == default(DateTime))
  26. {
  27. return offerDuration;
  28. }
  29. return offerDuration - (DateTime.Now - impressionDate);
  30. }
  31. }
  32. public bool isExpired
  33. {
  34. get
  35. {
  36. if (impressionDate == default(DateTime))
  37. {
  38. return false;
  39. }
  40. return timeRemaining.CompareTo(TimeSpan.FromSeconds(0)) <= 0;
  41. }
  42. }
  43. public PromoItem cost => costs != null && costs.Length > 0 ? costs[0] : default(PromoItem);
  44. public PromoItem payout => payouts != null && payouts.Length > 0 ? payouts[0] : default(PromoItem);
  45. }
  46. }