#if UNITY_EDITOR using System; using Azerion.BlueStack.API; using Azerion.BlueStack.Internal; using UnityEngine; namespace Azerion.BlueStack.Platforms.UnityEditor { public class NativeAdClient : BaseAdClient, INativeAdClient, IDisposable { private string _placementId; // Fires when the Native ad is loaded public event EventHandler OnNativeAdDidLoad; // Fires when the Native ad has failed to load public event EventHandler OnNativeAdDidFail; // Fires when the Native ad records impression public event EventHandler OnNativeAdImpression; // Fires when the Native ad is clicked public event EventHandler OnNativeAdClicked; // Fires when the Native ad is opening // public event EventHandler OnNativeAdOpening; //TODO // Fires when the Native ad is closed public event EventHandler OnNativeAdClosed; // Creates a Native Ad public void Create(string placementId) { _placementId = placementId; } // Loads a Native Ad public void Load() { // A simple placementId check to demonstrate load events if (string.IsNullOrEmpty(_placementId)) { OnNativeAdDidFail?.Invoke(this, new BlueStackError(-1, "Ad could not be loaded, wrong placement id")); } else { OnNativeAdDidLoad?.Invoke(this, EventArgs.Empty); } } // Loads an Interstitial Ad with preference, NOT implemented for editor public void Load(IPreferenceClient iPreferenceClient) { Load(); } public string GetTitle() { return "Native Test Title"; } public string GetBodyText() { return "Native Test Body Text: BlueStack supports native ads, that allow you to retrieve the metadata of ad campaigns and present the ads yourself, within the context of your app, using your own art style. You are fully responsible for rendering the ad views using the information we supply. Native ads however offer methods to help you register impressions and clicks on your custom view."; } public string GetCallToActionText() { return "Action"; } public byte[] GetBadgeBytes() { return new byte[] { }; } public string GetBadge() { return "Ad"; } public string GetIconUrl() { return "https://creative.mng-ads.com/10/10394-15539.jpg"; } public string GetCoverImageUrl() { return "https://creative.mng-ads.com/10/10394-15540.jpg"; } public string GetClickUrl() { return "https://developers.bluestack.app/"; } public void RecordImpression() { Debug.Log("Unity Native Ad Client : Impression Recorded!"); OnNativeAdImpression?.Invoke(this, EventArgs.Empty); } public void PerformClick() { OpenURL(GetClickUrl()); OnNativeAdClicked?.Invoke(this, EventArgs.Empty); } private void OpenURL(string clickUrl) { Debug.Log("Opened URL"); Application.OpenURL(clickUrl); } public void Close() { Debug.LogWarning("Unity Native Ad Client : Close!"); OnNativeAdClosed?.Invoke(this, EventArgs.Empty); } // Destroys a Native Ad public void Destroy() { _placementId = null; AdBehaviour.DestroyAd(dummyAd); adPrefab = null; } public void Dispose() { Destroy(); } } } #endif