void Awake () { // Create a native ad request with a unique placement ID (generate your own on the Facebook app settings). // Use different ID for each ad placement in your app. NativeAd nativeAd = new AudienceNetwork.NativeAd ("YOUR_PLACEMENT_ID"); this.nativeAd = nativeAd; // Wire up GameObject with the native ad; the specified buttons will be clickable. nativeAd.RegisterGameObjectForImpression (gameObject, new Button[] { callToActionButton }); // Set delegates to get notified on changes or when the user interacts with the ad. nativeAd.NativeAdDidLoad = (delegate() { Debug.Log ("Native ad loaded."); Debug.Log ("Loading images..."); // Use helper methods to load images from native ad URLs StartCoroutine (nativeAd.LoadIconImage (nativeAd.IconImageURL)); StartCoroutine (nativeAd.LoadCoverImage (nativeAd.CoverImageURL)); Debug.Log ("Images loaded."); title.text = nativeAd.Title; socialContext.text = nativeAd.SocialContext; callToAction.text = nativeAd.CallToAction; }); nativeAd.NativeAdDidFailWithError = (delegate(string error) { Debug.Log ("Native ad failed to load with error: " + error); }); nativeAd.NativeAdWillLogImpression = (delegate() { Debug.Log ("Native ad logged impression."); }); nativeAd.NativeAdDidClick = (delegate() { Debug.Log ("Native ad clicked."); }); // Initiate a request to load an ad. nativeAd.LoadAd (); }
public virtual int Load(int uniqueId) { NativeAd nativeAd = this.nativeAds [uniqueId]; nativeAd.loadAdFromData(); return(uniqueId); }
public override int Create(string placementId, NativeAd nativeAd) { AdUtility.prepare(); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject context = currentActivity.Call <AndroidJavaObject>("getApplicationContext"); AndroidJavaObject bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", context, placementId); NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy(nativeAd, bridgedNativeAd); bridgedNativeAd.Call("setAdListener", proxy); NativeAdBridgeImpressionListenerProxy impressionListenerProxy = new NativeAdBridgeImpressionListenerProxy(nativeAd, bridgedNativeAd); bridgedNativeAd.Call("setImpressionListener", impressionListenerProxy); NativeAdContainer nativeAdContainer = new NativeAdContainer(nativeAd); nativeAdContainer.bridgedNativeAd = bridgedNativeAd; nativeAdContainer.listenerProxy = proxy; nativeAdContainer.impressionListenerProxy = impressionListenerProxy; int key = NativeAdBridgeAndroid.lastKey; NativeAdBridgeAndroid.nativeAds.Add(key, nativeAdContainer); NativeAdBridgeAndroid.lastKey++; return(key); }
#pragma warning disable 162 public void LoadNativeAds(string placementID) { #if UNITY_ANDROID || UNITY_IPHONE if (impressionCamera == null) { Debug.LogWarning("Impression camera for native ads is null, no native ads will be created"); return; } #if UNITY_EDITOR //#if UNITY_ANDROID // //only run on device // //#elif UNITY_IOS //#endif //#else return; #endif //AdSettings.AddTestDevice("4b55fbfb8fb5b2f91ef8ac3a2d44fd9e"); // Create a native ad request with a unique placement ID (generate your own on the Facebook app settings). // Use different ID for each ad placement in your app. NativeAd nativeAd = new AudienceNetwork.NativeAd(placementID); this.nativeAd = nativeAd; //print("Loading native ads with ID " + placementID); nativeAd.RegisterGameObjectForImpression(gameObject, new UIButton[] { btnCall2Action }, impressionCamera); nativeAd.NativeAdDidLoad = OnNativeAdLoaded; nativeAd.NativeAdDidFailWithError = OnNativeAdLoadFailed; nativeAd.NativeAdWillLogImpression = OnNativeAdWillLogImpression; nativeAd.NativeAdDidClick = OnNativeAdClicked; nativeAd.LoadAd(); //// Set delegates to get notified on changes or when the user interacts with the ad. //nativeAd.NativeAdDidLoad = (delegate () { // print("+++++++++======Native ad loaded."); // Debug.Log("Loading images..."); // // Use helper methods to load images from native ad URLs // StartCoroutine(nativeAd.LoadIconImage(nativeAd.IconImageURL)); // StartCoroutine(nativeAd.LoadCoverImage(nativeAd.CoverImageURL)); // Debug.Log("Images loaded."); // txtTitle.text = nativeAd.Title; // txtSocialContext.text = nativeAd.SocialContext; // txtCall2Action.text = nativeAd.CallToAction; //}); //nativeAd.NativeAdDidFailWithError = (delegate (string error) { // print("++++++=====Native ad failed to load with error: " + error); //}); //nativeAd.NativeAdWillLogImpression = (delegate () { // print("++++++++=====Native ad logged impression."); //}); //nativeAd.NativeAdDidClick = (delegate () { // print("+++++++=====Native ad clicked."); //}); Debug.Log("=====+++++++LOADING NATIVE ADS with ID " + placementID); #endif }
public void SetNativeAd(NativeAd nativeAd) { image.sprite = nativeAd.AdChoicesImage; text.text = nativeAd.AdChoicesText; linkURL = nativeAd.AdChoicesLinkURL; canvasGroup.alpha = 1f; canvasGroup.interactable = true; }
public void SetNativeAd(NativeAd nativeAd) { this.image.set_sprite(nativeAd.AdChoicesImage); this.text.text = nativeAd.AdChoicesText; this.linkURL = nativeAd.AdChoicesLinkURL; this.canvasGroup.alpha = 1f; this.canvasGroup.interactable = true; }
public override int Create(string placementId, NativeAd nativeAd) { int uniqueId = NativeAdBridgeIOS.FBNativeAdBridgeCreate(placementId); NativeAdBridgeIOS.nativeAds.Add(uniqueId, new NativeAdContainer(nativeAd)); NativeAdBridgeIOS.FBNativeAdBridgeOnLoad(uniqueId, nativeAdDidLoadBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnImpression(uniqueId, nativeAdWillLogImpressionBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnClick(uniqueId, nativeAdDidClickBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnError(uniqueId, nativeAdDidFailWithErrorBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnFinishedClick(uniqueId, nativeAdDidFinishHandlingClickBridgeCallback); return(uniqueId); }
public IEnumerator LoadIconImage(string url) { Texture2D texture = new Texture2D(4, 4, NativeAd.imageFormat(), false); WWW www = new WWW(url); yield return(www); www.LoadImageIntoTexture(texture); if (texture) { this.IconImage = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); } }
public virtual int Load(int uniqueId) { NativeAd nativeAd = this.nativeAds [uniqueId]; nativeAd.loadAdFromData(); var callback = this.onLoadCallback; if (callback != null) { callback(); } return(uniqueId); }
// Load Ad button public void LoadAd() { // Create a native ad request with a unique placement ID (generate your own on the Facebook app settings). // Use different ID for each ad placement in your app. NativeAd nativeAd = new AudienceNetwork.NativeAd("YOUR_PLACEMENT_ID"); this.nativeAd = nativeAd; // Wire up GameObject with the native ad; the specified buttons will be clickable. if (targetAdObject) { if (targetButton) { nativeAd.RegisterGameObjectForImpression(targetAdObject, new Button[] { targetButton }); } else { nativeAd.RegisterGameObjectForImpression(targetAdObject, new Button[] { }); } } else { nativeAd.RegisterGameObjectForImpression(gameObject, new Button[] { }); } // Set delegates to get notified on changes or when the user interacts with the ad. nativeAd.NativeAdDidLoad = (delegate() { adLoaded = true; Debug.Log("Native ad loaded."); Debug.Log("Loading images..."); // Use helper methods to load images from native ad URLs StartCoroutine(nativeAd.LoadCoverImage(nativeAd.CoverImageURL)); StartCoroutine(nativeAd.LoadIconImage(nativeAd.IconImageURL)); Debug.Log("Images loaded."); }); nativeAd.NativeAdDidFailWithError = (delegate(string error) { Debug.Log("Native ad failed to load with error: " + error); }); nativeAd.NativeAdWillLogImpression = (delegate() { Debug.Log("Native ad logged impression."); }); nativeAd.NativeAdDidClick = (delegate() { Debug.Log("Native ad clicked."); }); // Initiate a request to load an ad. nativeAd.LoadAd(); Debug.Log("Native ad loading..."); }
private void StartNativeAd() { Debug.Log("StartNativeAd"); NativeAd nativeAd = new AudienceNetwork.NativeAd(uniqueId); this.nativeAd = nativeAd; nativeAd.RegisterGameObjectForImpression(gameObject, new Button[] { callToActionButton }); coverImage.sprite = null; iconImage.sprite = null; // 原生广告加载结束 nativeAd.NativeAdDidLoad = (delegate() { this.Log("Native ad loaded."); Debug.Log("Loading images..."); // Use helper methods to load images from native ad URLs StartCoroutine(nativeAd.LoadIconImage(nativeAd.IconImageURL)); StartCoroutine(nativeAd.LoadCoverImage(nativeAd.CoverImageURL)); Debug.Log("Images loaded."); title.text = nativeAd.Title; socialContext.text = nativeAd.SocialContext; callToAction.text = nativeAd.CallToAction; onNativeAdAdDidLoad.Invoke(); }); // 加载过程中出现错误 nativeAd.NativeAdDidFailWithError = (delegate(string error) { this.Log("Native ad failed to load with error: " + error); onNativeAdAdDidFailWithError.Invoke(error); }); // 广告日志记录 nativeAd.NativeAdWillLogImpression = (delegate() { this.Log("Native ad logged impression."); }); // 点击广告 nativeAd.NativeAdDidClick = (delegate() { this.Log("Native ad clicked."); onNativeAdAdDidClick.Invoke(); }); nativeAd.NativeAdDidFinishHandlingClick = (delegate() { this.Log("Native ad Did Finish Handling Click."); }); nativeAd.LoadAd(); }
void loadAd() { //hide the game object while its loading adUnit.container.SetActive(false); // Create a native ad request with a unique placement ID (generate your own on the Facebook app settings). // Use different ID for each ad placement in your app. NativeAd nativeAd = new AudienceNetwork.NativeAd("681585495338680_681600238670539"); this.nativeAd = nativeAd; // Wire up GameObject with the native ad; the specified buttons will be clickable. nativeAd.RegisterGameObjectForImpression(adUnit.container, new Button[] { adUnit.callToActionButton }); // Set delegates to get notified on changes or when the user interacts with the ad. nativeAd.NativeAdDidLoad = (delegate() { Debug.Log("Native ad loaded."); // Make container visable adUnit.container.SetActive(true); adUnit.title.text = nativeAd.Title; adUnit.socialContext.text = nativeAd.SocialContext; adUnit.callToAction.text = nativeAd.CallToAction; Debug.Log("Loading images..."); StartCoroutine(nativeAd.LoadIconImage(nativeAd.IconImageURL)); StartCoroutine(nativeAd.LoadCoverImage(nativeAd.CoverImageURL)); Debug.Log("Images loaded."); }); nativeAd.NativeAdDidFailWithError = (delegate(string error) { Debug.Log("Native ad failed to load with error: " + error); }); nativeAd.NativeAdWillLogImpression = (delegate() { Debug.Log("Native ad logged impression."); }); nativeAd.NativeAdDidClick = (delegate() { Debug.Log("Native ad clicked."); }); // Initiate a request to load an ad. nativeAd.LoadAd(); Debug.Log("Native ad loading..."); }
public override int Create(string placementId, NativeAd nativeAd) { AdUtility.prepare(); AndroidJavaClass androidJavaClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject @static = androidJavaClass.GetStatic <AndroidJavaObject>("currentActivity"); AndroidJavaObject androidJavaObject = @static.Call <AndroidJavaObject>("getApplicationContext", new object[0]); AndroidJavaObject androidJavaObject2 = new AndroidJavaObject("com.facebook.ads.NativeAd", androidJavaObject, placementId); NativeAdBridgeListenerProxy nativeAdBridgeListenerProxy = new NativeAdBridgeListenerProxy(nativeAd, androidJavaObject2); androidJavaObject2.Call("setAdListener", nativeAdBridgeListenerProxy); NativeAdContainer nativeAdContainer = new NativeAdContainer(nativeAd); nativeAdContainer.bridgedNativeAd = androidJavaObject2; nativeAdContainer.listenerProxy = nativeAdBridgeListenerProxy; int num = lastKey; nativeAds.Add(num, nativeAdContainer); lastKey++; return(num); }
public override int Create(string placementId, NativeAd nativeAd) { AdUtility.prepare(); AndroidJavaClass class2 = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject obj3 = class2.GetStatic <AndroidJavaObject>("currentActivity").Call <AndroidJavaObject>("getApplicationContext", new object[0]); object[] args = new object[] { obj3, placementId }; AndroidJavaObject bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", args); NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy(nativeAd, bridgedNativeAd); object[] objArray2 = new object[] { proxy }; bridgedNativeAd.Call("setAdListener", objArray2); NativeAdContainer container = new NativeAdContainer(nativeAd) { bridgedNativeAd = bridgedNativeAd, listenerProxy = proxy }; int lastKey = NativeAdBridgeAndroid.lastKey; nativeAds.Add(lastKey, container); NativeAdBridgeAndroid.lastKey++; return(lastKey); }
internal NativeAdContainer (NativeAd nativeAd) { this.nativeAd = nativeAd; }
public virtual int Create(string placementId, NativeAd nativeAd) { nativeAds.Add(nativeAd); return(nativeAds.Count - 1); }
#pragma warning restore 0414 public NativeAdBridgeImpressionListenerProxy(NativeAd nativeAd, AndroidJavaObject bridgedNativeAd) : base("com.facebook.ads.ImpressionListener") { this.nativeAd = nativeAd; this.bridgedNativeAd = bridgedNativeAd; }
internal NativeAdContainer(NativeAd nativeAd) { this.nativeAd = nativeAd; }
#pragma warning restore 0414 public NativeAdBridgeListenerProxy(NativeAd nativeAd, AndroidJavaObject bridgedNativeAd) : base("com.facebook.ads.AdListener") { this.nativeAd = nativeAd; this.bridgedNativeAd = bridgedNativeAd; }
public override int Create (string placementId, NativeAd nativeAd) { int uniqueId = NativeAdBridgeIOS.FBNativeAdBridgeCreate (placementId); NativeAdBridgeIOS.nativeAds.Add (uniqueId, new NativeAdContainer(nativeAd)); NativeAdBridgeIOS.FBNativeAdBridgeOnLoad (uniqueId, nativeAdDidLoadBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnImpression (uniqueId, nativeAdWillLogImpressionBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnClick (uniqueId, nativeAdDidClickBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnError (uniqueId, nativeAdDidFailWithErrorBridgeCallback); NativeAdBridgeIOS.FBNativeAdBridgeOnFinishedClick (uniqueId, nativeAdDidFinishHandlingClickBridgeCallback); return uniqueId; }
public override int Create (string placementId, NativeAd nativeAd) { AdUtility.prepare (); AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity"); AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext"); AndroidJavaObject bridgedNativeAd = new AndroidJavaObject("com.facebook.ads.NativeAd", context, placementId); NativeAdBridgeListenerProxy proxy = new NativeAdBridgeListenerProxy (nativeAd, bridgedNativeAd); bridgedNativeAd.Call ("setAdListener", proxy); NativeAdContainer nativeAdContainer = new NativeAdContainer (nativeAd); nativeAdContainer.bridgedNativeAd = bridgedNativeAd; nativeAdContainer.listenerProxy = proxy; int key = NativeAdBridgeAndroid.lastKey; NativeAdBridgeAndroid.nativeAds.Add(key, nativeAdContainer); NativeAdBridgeAndroid.lastKey++; return key; }
public virtual int Create (string placementId, NativeAd nativeAd) { nativeAds.Add (nativeAd); return nativeAds.Count - 1; }