// Load Ad button public void LoadAd() { statusText.text = "LoadAd"; if (nativeAd == null) { // you must set native express ad view transform if you want to support native express ad NativeAdOptionsBuilder builder = new NativeAdOptionsBuilder(); builder.setExpressAdViewTransform(adPanel.transform); YumiNativeAdOptions options = new YumiNativeAdOptions(builder); //YumiNativeAdOptions options = new NativeAdOptionsBuilder().Build(); // only native nativeAd = new YumiNativeAd(NativePlacementId, ChannelId, GameVersionId, gameObject, options); nativeAd.OnNativeAdLoaded += HandleNativeAdLoaded; nativeAd.OnAdFailedToLoad += HandleNativeAdFailedToLoad; nativeAd.OnAdClick += HandleNativeAdClicked; nativeAd.OnExpressAdRenderSuccess += HandleNativeExpressAdRenderSuccess; nativeAd.OnExpressAdRenderFail += HandleNativeExpressAdRenderFail; nativeAd.OnExpressAdClickCloseButton += HandleNativeExpressAdClickCloseButton; } UnregisterNativeViews(); nativeAd.LoadAd(1); }
// Creates a native ad public void CreateNativeAd(string placementId, string channelId, string versionId, GameObject gameObject, YumiNativeAdOptions option) { this.nativeClientPtr = (IntPtr)GCHandle.Alloc(this); this.currentGameObject = gameObject; Camera camera = Camera.main; int expressAdViewWidth = 0; int expressAdViewHeight = 0; if (option.expressAdViewTransform != null) { Rect adViewRect = getGameObjectRect(option.expressAdViewTransform as RectTransform, camera); expressAdViewWidth = (int)adViewRect.width; expressAdViewHeight = (int)adViewRect.height; } this.NativeAdPtr = YumiExterns.InitYumiNativeAd(this.nativeClientPtr, placementId, channelId, versionId, (int)option.adChoiseViewPosition, (int)option.adAttribution.AdOptionsPosition, option.adAttribution.text, option.adAttribution.textColor, option.adAttribution.backgroundColor, option.adAttribution.textSize, option.adAttribution.hide, expressAdViewWidth, expressAdViewHeight); adOptions = option; YumiExterns.SetNativeCallbacks( this.NativeAdPtr, NativeDidReceiveAdCallback, NativeDidFailToReceiveAdWithErrorCallback, NativeDidClickCallback, NativeExpressAdDidRenderSuccessCallback, NativeExpressAdDidRenderFailCallback, NativeExpressAdDidClickCloseButtonCallback ); }
public void CreateNativeAd(string placementId, string channelId, string versionId, GameObject gameObject, YumiNativeAdOptions options) { currentGameObject = gameObject; this.options = options; Camera camera = Camera.main; int expressAdViewWidth = 0; int expressAdViewHeight = 0; if (options.expressAdViewTransform != null) { Rect adViewRect = getGameObjectRect(options.expressAdViewTransform as RectTransform, camera); expressAdViewWidth = (int)adViewRect.width; expressAdViewHeight = (int)adViewRect.height; } AdAttribution aab = options.adAttribution; TextOptions titleOps = options.titleTextOptions; TextOptions ctaOps = options.callToActionTextOptions; TextOptions descOps = options.descTextOptions; nativeAd.Call("create", placementId, channelId, versionId, // int adChosePosition, (int)options.adChoiseViewPosition, // int attriPosition, String attriText, int attriTextSize, String attriTextColor, String attriTextBackgroundColor (int)aab.AdOptionsPosition, aab.text, aab.textSize, getColorString(aab.textColor), getColorString(aab.backgroundColor), // int titleSize, String titleColor, String titleBackgroundColor, titleOps.textSize, getColorString(titleOps.textColor), getColorString(titleOps.backgroundColor), // int descSize, String descColor, String descBackgroundColor descOps.textSize, getColorString(descOps.textColor), getColorString(descOps.backgroundColor), // int ctaSize, String ctaColor, String ctaBackgroundColor, ctaOps.textSize, getColorString(ctaOps.textColor), getColorString(ctaOps.backgroundColor), // int iconScaleType, int coverImageScaleType (int)options.iconScaleType, (int)options.coverImageScaleType, expressAdViewWidth, expressAdViewHeight); Logger.Log("YumiUNativeAd unity: create 2"); }
// native ad // Creates a native ad public void CreateNativeAd(string placementId, string channelId, string versionId, GameObject gameObject, YumiNativeAdOptions options) { Logger.LogError("Dummy: call CreateNativeAd"); }