示例#1
0
        public override int Create(string placementId,
                                   AdView adView,
                                   AdSize size)
        {
            AdUtility.prepare();
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context         = currentActivity.Call <AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedAdView = new AndroidJavaObject("com.facebook.ads.AdView",
                                                                    context,
                                                                    placementId,
                                                                    javaAdSizeFromAdSize(size));

            AdViewBridgeListenerProxy proxy = new AdViewBridgeListenerProxy(adView, bridgedAdView);

            bridgedAdView.Call("setAdListener", proxy);

            AdViewBridgeImpressionListenerProxy impressionListenerProxy = new AdViewBridgeImpressionListenerProxy(adView, bridgedAdView);

            bridgedAdView.Call("setImpressionListener", impressionListenerProxy);

            AdViewContainer adViewContainer = new AdViewContainer(adView);

            adViewContainer.bridgedAdView           = bridgedAdView;
            adViewContainer.listenerProxy           = proxy;
            adViewContainer.impressionListenerProxy = impressionListenerProxy;

            int key = AdViewBridgeAndroid.lastKey;

            AdViewBridgeAndroid.adViews.Add(key, adViewContainer);
            AdViewBridgeAndroid.lastKey++;
            return(key);
        }
        public override int Create (string placementId,
                                    AdView adView,
                                    AdSize size)
        {
            AdUtility.prepare ();
            AndroidJavaClass unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
            AndroidJavaObject context = currentActivity.Call<AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedAdView = new AndroidJavaObject("com.facebook.ads.AdView",
                                                                    context,
                                                                    placementId,
                                                                    javaAdSizeFromAdSize (size));

            AdViewBridgeListenerProxy proxy = new AdViewBridgeListenerProxy (adView, bridgedAdView);
            bridgedAdView.Call ("setAdListener", proxy);

            AdViewBridgeImpressionListenerProxy impressionListenerProxy = new AdViewBridgeImpressionListenerProxy (adView, bridgedAdView);
            bridgedAdView.Call ("setImpressionListener", impressionListenerProxy);

            AdViewContainer adViewContainer = new AdViewContainer (adView);
            adViewContainer.bridgedAdView = bridgedAdView;
            adViewContainer.listenerProxy = proxy;
            adViewContainer.impressionListenerProxy = impressionListenerProxy;

            int key = AdViewBridgeAndroid.lastKey;
            AdViewBridgeAndroid.adViews.Add(key, adViewContainer);
            AdViewBridgeAndroid.lastKey++;
            return key;
        }