Пример #1
0
        public override int Create(string placementId,
                                   InterstitialAd interstitialAd)
        {
            AdUtility.prepare();
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context         = currentActivity.Call <AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedInterstitialAd = new AndroidJavaObject("com.facebook.ads.InterstitialAd", context, placementId);

            InterstitialAdBridgeListenerProxy proxy = new InterstitialAdBridgeListenerProxy(interstitialAd, bridgedInterstitialAd);

            bridgedInterstitialAd.Call("setAdListener", proxy);

            InterstitialAdBridgeImpressionListenerProxy impressionListenerProxy = new InterstitialAdBridgeImpressionListenerProxy(interstitialAd, bridgedInterstitialAd);

            bridgedInterstitialAd.Call("setImpressionListener", impressionListenerProxy);

            InterstitialAdContainer interstitialAdContainer = new InterstitialAdContainer(interstitialAd);

            interstitialAdContainer.bridgedInterstitialAd   = bridgedInterstitialAd;
            interstitialAdContainer.listenerProxy           = proxy;
            interstitialAdContainer.impressionListenerProxy = impressionListenerProxy;

            int key = InterstitialAdBridgeAndroid.lastKey;

            InterstitialAdBridgeAndroid.interstitialAds.Add(key, interstitialAdContainer);
            InterstitialAdBridgeAndroid.lastKey++;
            return(key);
        }
        public override int Create (string placementId,
                                    InterstitialAd interstitialAd)
        {
            AdUtility.prepare ();
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedInterstitialAd = new AndroidJavaObject("com.facebook.ads.InterstitialAd", context, placementId);

            InterstitialAdBridgeListenerProxy proxy = new InterstitialAdBridgeListenerProxy (interstitialAd, bridgedInterstitialAd);
            bridgedInterstitialAd.Call ("setAdListener", proxy);

            InterstitialAdBridgeImpressionListenerProxy impressionListenerProxy = new InterstitialAdBridgeImpressionListenerProxy (interstitialAd, bridgedInterstitialAd);
            bridgedInterstitialAd.Call ("setImpressionListener", impressionListenerProxy);

            InterstitialAdContainer interstitialAdContainer = new InterstitialAdContainer (interstitialAd);
            interstitialAdContainer.bridgedInterstitialAd = bridgedInterstitialAd;
            interstitialAdContainer.listenerProxy = proxy;
            interstitialAdContainer.impressionListenerProxy = impressionListenerProxy;

            int key = InterstitialAdBridgeAndroid.lastKey;
            InterstitialAdBridgeAndroid.interstitialAds.Add(key, interstitialAdContainer);
            InterstitialAdBridgeAndroid.lastKey++;
            return key;
        }