Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

139 строки
3.9 KiB

  1. // Copyright (C) 2015 Google, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #if UNITY_ANDROID
  15. using System;
  16. using GoogleMobileAds.Api;
  17. using GoogleMobileAds.Common;
  18. using UnityEngine;
  19. namespace GoogleMobileAds.Android
  20. {
  21. public class InterstitialClient : AndroidJavaProxy, IInterstitialClient
  22. {
  23. private AndroidJavaObject interstitial;
  24. public InterstitialClient() : base(Utils.UnityAdListenerClassName)
  25. {
  26. AndroidJavaClass playerClass = new AndroidJavaClass(Utils.UnityActivityClassName);
  27. AndroidJavaObject activity =
  28. playerClass.GetStatic<AndroidJavaObject>("currentActivity");
  29. this.interstitial = new AndroidJavaObject(
  30. Utils.InterstitialClassName, activity, this);
  31. }
  32. public event EventHandler<EventArgs> OnAdLoaded;
  33. public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
  34. public event EventHandler<EventArgs> OnAdOpening;
  35. public event EventHandler<EventArgs> OnAdClosed;
  36. public event EventHandler<EventArgs> OnAdLeavingApplication;
  37. #region IGoogleMobileAdsInterstitialClient implementation
  38. // Creates an interstitial ad.
  39. public void CreateInterstitialAd(string adUnitId)
  40. {
  41. this.interstitial.Call("create", adUnitId);
  42. }
  43. // Loads an ad.
  44. public void LoadAd(AdRequest request)
  45. {
  46. this.interstitial.Call("loadAd", Utils.GetAdRequestJavaObject(request));
  47. }
  48. // Checks if interstitial has loaded.
  49. public bool IsLoaded()
  50. {
  51. return this.interstitial.Call<bool>("isLoaded");
  52. }
  53. // Presents the interstitial ad on the screen.
  54. public void ShowInterstitial()
  55. {
  56. this.interstitial.Call("show");
  57. }
  58. // Destroys the interstitial ad.
  59. public void DestroyInterstitial()
  60. {
  61. this.interstitial.Call("destroy");
  62. }
  63. // Returns the mediation adapter class name.
  64. public string MediationAdapterClassName()
  65. {
  66. return this.interstitial.Call<string>("getMediationAdapterClassName");
  67. }
  68. #endregion
  69. #region Callbacks from UnityInterstitialAdListener.
  70. public void onAdLoaded()
  71. {
  72. if (this.OnAdLoaded != null)
  73. {
  74. this.OnAdLoaded(this, EventArgs.Empty);
  75. }
  76. }
  77. public void onAdFailedToLoad(string errorReason)
  78. {
  79. if (this.OnAdFailedToLoad != null)
  80. {
  81. AdFailedToLoadEventArgs args = new AdFailedToLoadEventArgs()
  82. {
  83. Message = errorReason
  84. };
  85. this.OnAdFailedToLoad(this, args);
  86. }
  87. }
  88. public void onAdOpened()
  89. {
  90. if (this.OnAdOpening != null)
  91. {
  92. this.OnAdOpening(this, EventArgs.Empty);
  93. }
  94. }
  95. public void onAdClosed()
  96. {
  97. if (this.OnAdClosed != null)
  98. {
  99. this.OnAdClosed(this, EventArgs.Empty);
  100. }
  101. }
  102. public void onAdLeftApplication()
  103. {
  104. if (this.OnAdLeavingApplication != null)
  105. {
  106. this.OnAdLeavingApplication(this, EventArgs.Empty);
  107. }
  108. }
  109. #endregion
  110. }
  111. }
  112. #endif