#if UNITY_EDITOR using System; using Azerion.BlueStack.API.Banner; using Azerion.BlueStack.API; using UnityEditor; using UnityEngine; using UnityEngine.UI; namespace Azerion.BlueStack.Platforms.UnityEditor { public class AdvertisementManager : MonoBehaviour { public static GameObject AdOverlay; public static GameObject AdBannerOverlay; public Text AdInfoTop; public Text AdInfoBottom; public static string adBannerInfoText; public static string adInfoText; public static string bannerProvider; public static string bannerAdType; private static string adType; private static string provider; private static readonly string _assetsDirPrefix = "Packages/com.azerion.bluestack/Editor/Prefabs"; public static event EventHandler OnAdClosed; public static event EventHandler OnUserRewardEarned; void Update() { if (adType != null) { AdInfoBottom.text = adInfoText; AdInfoTop.text = adInfoText; } else if (bannerAdType != null) { AdInfoBottom.text = adBannerInfoText; AdInfoTop.text = adBannerInfoText; } } public static void ShowBannerAd(AdPosition position, AdSize adSize) { #if UNITY_WEBGL || UNITY_STANDALONE Debug.LogWarning("BlueStack doesn't support WegGL or PC ads at the moment."); #else AdBannerOverlay = (GameObject)Instantiate( AssetDatabase.LoadAssetAtPath( _assetsDirPrefix + "/AdBannerOverlay.prefab")); AdBannerOverlay.SetActive(true); bannerProvider = "BlueStack"; bannerAdType = "BannerAd"; adBannerInfoText = bannerProvider + " " + bannerAdType + " is showing!"; GameObject BannerTop = AdBannerOverlay.transform.Find("BannerTop").gameObject; GameObject BannerBottom = AdBannerOverlay.transform.Find("BannerBottom").gameObject; if (position != AdPosition.Bottom) { BannerTop.SetActive(true); BannerBottom.SetActive(false); } if (adSize == AdSize.Banner) { BannerTop.transform.localScale = new Vector3(BannerTop.transform.localScale.x * 0.5f, BannerTop.transform.localScale.y, BannerTop.transform.localScale.z); BannerBottom.transform.localScale = new Vector3(BannerBottom.transform.localScale.x * 0.5f, BannerBottom.transform.localScale.y, BannerBottom.transform.localScale.z); } #endif } public static void DestroyBannerAd() { bannerAdType = null; Destroy(AdBannerOverlay); GameObject bannerOverlay = GameObject.Find("AdBannerOverlay(Clone)"); if (bannerOverlay != null) { Destroy(bannerOverlay); } } public static void ShowInterstitialAd() { #if UNITY_WEBGL || UNITY_STANDALONE Debug.LogWarning("BlueStack doesn't support WegGL or PC ads at the moment."); #else AdOverlay = (GameObject)Instantiate( AssetDatabase.LoadAssetAtPath(_assetsDirPrefix + "/AdOverlay.prefab")); AdOverlay.SetActive(true); provider = "BlueStack"; adType = "InterstitialAd"; adInfoText = provider + " " + adType + " is playing!"; #endif } public static void ShowRewardedAd() { #if UNITY_WEBGL || UNITY_STANDALONE Debug.LogWarning("AzerionAds doesn't support WegGL or PC ads at the moment."); #else AdOverlay = (GameObject)Instantiate( AssetDatabase.LoadAssetAtPath(_assetsDirPrefix + "/AdOverlay.prefab")); AdOverlay.SetActive(true); provider = "BlueStack"; adType = "RewardedVideoAd"; adInfoText = provider + " " + adType + " is playing!"; #endif } public void CloseAd() { Debug.Log("Close Ad!"); if (adType == "RewardedVideoAd") { var rewardItem = new RewardedItem(10); OnUserRewardEarned?.Invoke(this, rewardItem); } provider = null; adType = null; Destroy(gameObject); OnAdClosed?.Invoke(this, EventArgs.Empty); } } } #endif