#if UNITY_EDITOR using System; using Azerion.BlueStack.API; using Azerion.BlueStack.Internal; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace Azerion.BlueStack.Platforms.UnityEditor { public class InterstitialAdClient : BaseAdClient, IInterstitialAdClient, IDisposable { private string _placementId; // Fires when the Interstitial ad is loaded public event EventHandler OnInterstitialDidLoaded; // Fires when the Interstitial ad has failed to load public event EventHandler OnInterstitialDidFail; // Fires when the Interstitial ad is clicked public event EventHandler OnInterstitialClicked; // Fires when the Interstitial ad is closed public event EventHandler OnInterstitialDisappear; // Fires when the Interstitial ad is shown public event EventHandler OnInterstitialDidShown; // Interstitial ad size private static readonly AdSize _interstitialPortrait = new AdSize(768, 1024, "768x1024"); private static readonly AdSize _interstitialLandscape = new AdSize(1024, 768, "1024x768"); private static readonly string _adPrefabsDir = "Packages/com.azerion.bluestack/Editor/Prefabs/AdPrefabs/"; private Dictionary _prefabAds = new Dictionary() { { _interstitialPortrait, _adPrefabsDir + "Interstitial/InterstitialPortrait.prefab" }, { _interstitialLandscape, _adPrefabsDir + "Interstitial/InterstitialLandscape.prefab" } }; // Creats an Interstitial Ad public void Create(string placementId) { this._placementId = placementId; } // Loads an Interstitial Ad public void Load() { if (Screen.width > Screen.height) //Landscape { LoadAndSetAdPrefab(_prefabAds[_interstitialLandscape]); } else { LoadAndSetAdPrefab(_prefabAds[_interstitialPortrait]); } if (adPrefab != null) { OnInterstitialDidLoaded?.Invoke(this, EventArgs.Empty); } else { OnInterstitialDidFail?.Invoke(this, new BlueStackError(-1, "Ad could not be loaded")); } } // Loads an Interstitial Ad with preference, NOT implemented for editor public void Load(IPreferenceClient iPreferenceClient) { Load(); } // Shows the Interstitial Ad public void Show() { if (adPrefab != null) { dummyAd = AdBehaviour.ShowAd(adPrefab, new Vector3(0, 0, 1)); AddClickBehavior(dummyAd); AdBehaviour.PauseGame(); OnInterstitialDidShown?.Invoke(this, EventArgs.Empty); } else { Debug.Log("Ad could not be shown"); } } // Destroys an Interstitial Ad public void Destroy() { this._placementId = null; AdBehaviour.DestroyAd(dummyAd); adPrefab = null; } public void Dispose() { Destroy(); } // Adding Ad click and close button actions private void AddClickBehavior(GameObject dummyAd) { Button[] buttons = dummyAd.GetComponentsInChildren