#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 RewardedVideoAdClient : BaseAdClient, IRewardedVideoAdClient, IDisposable { private string _placementId; // Fires when the Rewarded ad is loaded public event EventHandler OnRewardedVideoLoaded; // Fires when the Rewarded ad has failed to load public event EventHandler OnRewardedVideoError; // Fires when the Rewarded ad is clicked public event EventHandler OnRewardedVideoClicked; // Fires when the Rewarded ad has appeared public event EventHandler OnRewardedVideoAppeared; // Fires when the Rewarded ad has rewarded the user public event EventHandler OnUserRewardEarned; // Fires when the Rewarded ad is closed public event EventHandler OnRewardedVideoClosed; // Rewarded ad size private static readonly AdSize _rewardedPortrait = new AdSize(768, 1024, "768x1024"); private static readonly AdSize _rewardedLandscape = new AdSize(1024, 768, "1024x768"); private static readonly string _adPrefabsDir = "Packages/com.azerion.bluestack/Editor/Prefabs/AdPrefabs/"; private Dictionary _prefabAds = new Dictionary() { { _rewardedPortrait, _adPrefabsDir + "Rewarded/RewardedPortrait.prefab" }, { _rewardedLandscape, _adPrefabsDir + "Rewarded/RewardedLandscape.prefab" } }; internal RewardedVideoAdClient() { } // Creats an Rewarded Ad public void Create(string placementId) { this._placementId = placementId; } // Loads an Rewarded Ad public void Load() { if (Screen.width > Screen.height) //Landscape { LoadAndSetAdPrefab(_prefabAds[_rewardedLandscape]); } else { LoadAndSetAdPrefab(_prefabAds[_rewardedPortrait]); } if (adPrefab != null) { OnRewardedVideoLoaded?.Invoke(this, EventArgs.Empty); } else { OnRewardedVideoError?.Invoke(this, new BlueStackError(-1, "Ad could not be loaded")); } } // Loads an Rewarded Ad with preference, NOT implemented for editor public void Load(IPreferenceClient iPreferenceClient) { Load(); } public void Show() { if (adPrefab != null) { dummyAd = AdBehaviour.ShowAd(adPrefab, new Vector3(0, 0, 1)); AdBehaviour.PauseGame(); AddClickBehavior(dummyAd); dummyAd.AddComponent(); RewardedTimer.OnUserRewardEarned += (sender, args) => { OnUserRewardEarned?.Invoke(this, args); }; OnRewardedVideoAppeared?.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