EditorPlacementContentOperations.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #if UNITY_EDITOR
  2. using System;
  3. using System.Collections.Generic;
  4. namespace UnityEngine.Monetization
  5. {
  6. public class EditorPlacementContentOperations : IPlacementContentOperations
  7. {
  8. public EditorPlacementContentOperations()
  9. {
  10. }
  11. public void SendCustomEvent(CustomEvent customEvent)
  12. {
  13. Debug.LogFormat("Sent custom event in editor: {0}", customEvent.ToString());
  14. }
  15. public bool ready => true;
  16. public PlacementContentState state => PlacementContentState.Ready;
  17. }
  18. public class EditorRewardedOperations : EditorPlacementContentOperations, IRewardedOperations
  19. {
  20. public EditorRewardedOperations() : base()
  21. {
  22. }
  23. public bool IsRewarded()
  24. {
  25. return true;
  26. }
  27. public string rewardId => "rewardId";
  28. }
  29. public class EditorShowAdOperations : EditorRewardedOperations, IShowAdOperations
  30. {
  31. public EditorShowAdOperations() : base()
  32. {
  33. }
  34. public bool allowSkip { get; set; }
  35. public string placementId {get; set; }
  36. private ShowAdCallbacks? _showOptions;
  37. public virtual void Show(ShowAdCallbacks? showOptions)
  38. {
  39. ShowWithPlacement("ShowAdPlacement", showOptions);
  40. }
  41. void StartHandler()
  42. {
  43. Platform.m_Placeholder.onStart -= StartHandler;
  44. _showOptions?.startCallback();
  45. }
  46. void FinishHandler(ShowResult result)
  47. {
  48. Platform.m_Placeholder.onFinish -= FinishHandler;
  49. _showOptions?.finishCallback(result);
  50. }
  51. protected void ShowWithPlacement(string placementId, ShowAdCallbacks? showOptions)
  52. {
  53. if (Platform.m_Placeholder != null)
  54. {
  55. _showOptions = showOptions;
  56. Platform.m_Placeholder.onStart += StartHandler;
  57. Platform.m_Placeholder.onFinish += FinishHandler;
  58. Platform.m_Placeholder.Show(placementId, allowSkip);
  59. }
  60. }
  61. }
  62. public class EditorPromoAdOperations : EditorShowAdOperations, IPromoAdOperations
  63. {
  64. public EditorPromoAdOperations() : base()
  65. {
  66. metadata = new PromoMetadata
  67. {
  68. impressionDate = DateTime.Now,
  69. offerDuration = TimeSpan.FromHours(3),
  70. premiumProduct = new Product
  71. {
  72. productId = "FakeProductId",
  73. localizedTitle = "Fake localized title",
  74. localizedDescription = "Fake localized description",
  75. localizedPrice = new decimal(1.99),
  76. localizedPriceString = "$1.99",
  77. isoCurrencyCode = "USD",
  78. productType = "FakeProductType"
  79. },
  80. costs = new PromoItem[] {},
  81. payouts = new PromoItem[] {},
  82. customInfo = new Dictionary<string, object>()
  83. };
  84. }
  85. public override void Show(ShowAdCallbacks? showOptions)
  86. {
  87. ShowWithPlacement("PromoAdPlacement", showOptions);
  88. }
  89. public PromoMetadata metadata { get; }
  90. }
  91. }
  92. #endif