コード例 #1
0
        public override int Create(string placementId, RewardData rewardData,
                                   RewardedVideoAd rewardedVideoAd)
        {
            AdUtility.Prepare();
            AndroidJavaClass  unityPlayer     = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
            AndroidJavaObject currentActivity = unityPlayer.GetStatic <AndroidJavaObject>("currentActivity");
            AndroidJavaObject context         = currentActivity.Call <AndroidJavaObject>("getApplicationContext");

            AndroidJavaObject bridgedRewardedVideoAd = new AndroidJavaObject("com.facebook.ads.RewardedVideoAd", context, placementId);

            RewardedVideoAdBridgeListenerProxy proxy = new RewardedVideoAdBridgeListenerProxy(rewardedVideoAd, bridgedRewardedVideoAd);

            bridgedRewardedVideoAd.Call("setAdListener", proxy);

            if (rewardData != null)
            {
                AndroidJavaObject rewardDataObj = new AndroidJavaObject("com.facebook.ads.RewardData", rewardData.UserId, rewardData.Currency);
                bridgedRewardedVideoAd.Call("setRewardData", rewardDataObj);
            }

            RewardedVideoAdContainer rewardedVideoAdContainer = new RewardedVideoAdContainer(rewardedVideoAd)
            {
                bridgedRewardedVideoAd = bridgedRewardedVideoAd,
                listenerProxy          = proxy
            };

            int key = RewardedVideoAdBridgeAndroid.lastKey;

            RewardedVideoAdBridgeAndroid.rewardedVideoAds.Add(key, rewardedVideoAdContainer);
            RewardedVideoAdBridgeAndroid.lastKey++;
            return(key);
        }
コード例 #2
0
        public override int Create(string placementId, RewardData rewardData,
                                   RewardedVideoAd rewardedVideoAd)
        {
            int uniqueId = 0;

            if (rewardData != null)
            {
                uniqueId = RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeCreateWithReward(placementId, rewardData.UserId, rewardData.Currency);
            }
            else
            {
                uniqueId = RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeCreate(placementId);
            }

            RewardedVideoAdBridgeIOS.rewardedVideoAds.Add(uniqueId, new RewardedVideoAdContainer(rewardedVideoAd));
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnLoad(uniqueId, rewardedVideoAdDidLoadBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnImpression(uniqueId, rewardedVideoAdWillLogImpressionBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnClick(uniqueId, rewardedVideoAdDidClickBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnError(uniqueId, rewardedVideoAdDidFailWithErrorBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnDidClose(uniqueId, rewardedVideoAdDidCloseBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnWillClose(uniqueId, rewardedVideoAdWillCloseBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnVideoComplete(uniqueId, rewardedVideoAdCompleteBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnServerRewardSuccess(uniqueId, rewardedVideoAdDidSucceedBridgeCallback);
            RewardedVideoAdBridgeIOS.FBRewardedVideoAdBridgeOnServerRewardFailure(uniqueId, rewardedVideoAdDidFailBridgeCallback);

            return(uniqueId);
        }
コード例 #3
0
        public override int Create(string placementId, RewardData rewardData, RewardedVideoAd rewardedVideoAd)
        {
            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 bridgedRewardedVideoAd = new AndroidJavaObject("com.facebook.ads.RewardedVideoAd", args);
            RewardedVideoAdBridgeListenerProxy proxy = new RewardedVideoAdBridgeListenerProxy(rewardedVideoAd, bridgedRewardedVideoAd);

            object[] objArray2 = new object[] { proxy };
            bridgedRewardedVideoAd.Call("setAdListener", objArray2);
            if (rewardData != null)
            {
                object[]          objArray3 = new object[] { rewardData.UserId, rewardData.Currency };
                AndroidJavaObject obj5      = new AndroidJavaObject("com.facebook.ads.RewardData", objArray3);
                object[]          objArray4 = new object[] { obj5 };
                bridgedRewardedVideoAd.Call("setRewardData", objArray4);
            }
            RewardedVideoAdContainer container = new RewardedVideoAdContainer(rewardedVideoAd)
            {
                bridgedRewardedVideoAd = bridgedRewardedVideoAd,
                listenerProxy          = proxy
            };
            int lastKey = RewardedVideoAdBridgeAndroid.lastKey;

            rewardedVideoAds.Add(lastKey, container);
            RewardedVideoAdBridgeAndroid.lastKey++;
            return(lastKey);
        }
コード例 #4
0
        public override int Create(string placementId, RewardData rewardData, RewardedVideoAd rewardedVideoAd)
        {
            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.RewardedVideoAd", androidJavaObject, placementId);
            RewardedVideoAdBridgeListenerProxy rewardedVideoAdBridgeListenerProxy = new RewardedVideoAdBridgeListenerProxy(rewardedVideoAd, androidJavaObject2);

            androidJavaObject2.Call("setAdListener", rewardedVideoAdBridgeListenerProxy);
            if (rewardData != null)
            {
                AndroidJavaObject androidJavaObject3 = new AndroidJavaObject("com.facebook.ads.RewardData", rewardData.UserId, rewardData.Currency);
                androidJavaObject2.Call("setRewardData", androidJavaObject3);
            }
            RewardedVideoAdContainer rewardedVideoAdContainer = new RewardedVideoAdContainer(rewardedVideoAd);

            rewardedVideoAdContainer.bridgedRewardedVideoAd = androidJavaObject2;
            rewardedVideoAdContainer.listenerProxy          = rewardedVideoAdBridgeListenerProxy;
            int num = lastKey;

            rewardedVideoAds.Add(num, rewardedVideoAdContainer);
            lastKey++;
            return(num);
        }
コード例 #5
0
 public RewardedVideoAd(string placementId, RewardData rewardData)
 {
     PlacementId = placementId;
     RewardData  = rewardData;
     if (Application.platform != 0)
     {
         uniqueId = RewardedVideoAdBridge.Instance.Create(placementId, RewardData, this);
         RewardedVideoAdBridge.Instance.OnLoad(uniqueId, RewardedVideoAdDidLoad);
         RewardedVideoAdBridge.Instance.OnImpression(uniqueId, RewardedVideoAdWillLogImpression);
         RewardedVideoAdBridge.Instance.OnClick(uniqueId, RewardedVideoAdDidClick);
         RewardedVideoAdBridge.Instance.OnError(uniqueId, RewardedVideoAdDidFailWithError);
         RewardedVideoAdBridge.Instance.OnWillClose(uniqueId, RewardedVideoAdWillClose);
         RewardedVideoAdBridge.Instance.OnDidClose(uniqueId, RewardedVideoAdDidClose);
         RewardedVideoAdBridge.Instance.OnComplete(uniqueId, RewardedVideoAdComplete);
         RewardedVideoAdBridge.Instance.OnDidSucceed(uniqueId, RewardedVideoAdDidSucceed);
         RewardedVideoAdBridge.Instance.OnDidFail(uniqueId, RewardedVideoAdDidFail);
     }
 }
コード例 #6
0
        public RewardedVideoAd(string placementId, RewardData rewardData)
        {
            AudienceNetworkAds.Initialize();

            PlacementId = placementId;
            RewardData  = rewardData;

            if (Application.platform != RuntimePlatform.OSXEditor)
            {
                uniqueId = RewardedVideoAdBridge.Instance.Create(placementId, RewardData, this);

                RewardedVideoAdBridge.Instance.OnLoad(uniqueId, RewardedVideoAdDidLoad);
                RewardedVideoAdBridge.Instance.OnImpression(uniqueId, RewardedVideoAdWillLogImpression);
                RewardedVideoAdBridge.Instance.OnClick(uniqueId, RewardedVideoAdDidClick);
                RewardedVideoAdBridge.Instance.OnError(uniqueId, RewardedVideoAdDidFailWithError);
                RewardedVideoAdBridge.Instance.OnWillClose(uniqueId, RewardedVideoAdWillClose);
                RewardedVideoAdBridge.Instance.OnDidClose(uniqueId, RewardedVideoAdDidClose);
                RewardedVideoAdBridge.Instance.OnComplete(uniqueId, RewardedVideoAdComplete);
                RewardedVideoAdBridge.Instance.OnDidSucceed(uniqueId, RewardedVideoAdDidSucceed);
                RewardedVideoAdBridge.Instance.OnDidFail(uniqueId, RewardedVideoAdDidFail);
                RewardedVideoAdBridge.Instance.OnActivityDestroyed(uniqueId, RewardedVideoAdActivityDestroyed);
            }
        }
コード例 #7
0
 public virtual int Create(string placementId, RewardData rewardData,
                           RewardedVideoAd RewardedVideoAd)
 {
     return(123);
 }
コード例 #8
0
    // Load button
    public void LoadRewardedVideo()
    {
        statusLabel.text = "Loading rewardedVideo ad...";

        // Create the rewarded video unit with a placement ID (generate your own on the Facebook app settings).
        // Use different ID for each ad placement in your app.
        rewardedVideoAd = new RewardedVideoAd("YOUR_PLACEMENT_ID");

        // For S2S validation you can create the rewarded video ad with the reward data
        // Refer to documentation here:
        // https://developers.facebook.com/docs/audience-network/android/rewarded-video#server-side-reward-validation
        // https://developers.facebook.com/docs/audience-network/ios/rewarded-video#server-side-reward-validation
        AudienceNetwork.RewardData rewardData = new AudienceNetwork.RewardData
        {
            UserId   = "USER_ID",
            Currency = "REWARD_ID"
        };
#pragma warning disable 0219
        RewardedVideoAd s2sRewardedVideoAd = new RewardedVideoAd("YOUR_PLACEMENT_ID", rewardData);
#pragma warning restore 0219

        rewardedVideoAd.Register(gameObject);

        // Set delegates to get notified on changes or when the user interacts with the ad.
        rewardedVideoAd.RewardedVideoAdDidLoad = delegate()
        {
            Debug.Log("RewardedVideo ad loaded.");
            isLoaded = true;
            didClose = false;
            string isAdValid = rewardedVideoAd.IsValid() ? "valid" : "invalid";
            statusLabel.text = "Ad loaded and is " + isAdValid + ". Click show to present!";
        };
        rewardedVideoAd.RewardedVideoAdDidFailWithError = delegate(string error)
        {
            Debug.Log("RewardedVideo ad failed to load with error: " + error);
            statusLabel.text = "RewardedVideo ad failed to load. Check console for details.";
        };
        rewardedVideoAd.RewardedVideoAdWillLogImpression = delegate()
        {
            Debug.Log("RewardedVideo ad logged impression.");
        };
        rewardedVideoAd.RewardedVideoAdDidClick = delegate()
        {
            Debug.Log("RewardedVideo ad clicked.");
        };

        // For S2S validation you need to register the following two callback
        // Refer to documentation here:
        // https://developers.facebook.com/docs/audience-network/android/rewarded-video#server-side-reward-validation
        // https://developers.facebook.com/docs/audience-network/ios/rewarded-video#server-side-reward-validation
        rewardedVideoAd.RewardedVideoAdDidSucceed = delegate()
        {
            Debug.Log("Rewarded video ad validated by server");
        };

        rewardedVideoAd.RewardedVideoAdDidFail = delegate()
        {
            Debug.Log("Rewarded video ad not validated, or no response from server");
        };

        rewardedVideoAd.RewardedVideoAdDidClose = delegate()
        {
            Debug.Log("Rewarded video ad did close.");
            didClose = true;
            if (rewardedVideoAd != null)
            {
                rewardedVideoAd.Dispose();
            }
        };

#if UNITY_ANDROID
        /*
         * Only relevant to Android.
         * This callback will only be triggered if the Rewarded Video activity
         * has been destroyed without being properly closed. This can happen if
         * an app with launchMode:singleTask (such as a Unity game) goes to
         * background and is then relaunched by tapping the icon.
         */
        rewardedVideoAd.RewardedVideoAdActivityDestroyed = delegate()
        {
            if (!didClose)
            {
                Debug.Log("Rewarded video activity destroyed without being closed first.");
                Debug.Log("Game should resume. User should not get a reward.");
            }
        };
#endif

        // Initiate the request to load the ad.
        rewardedVideoAd.LoadAd();
    }
コード例 #9
0
 public virtual int Create(string placementId, RewardData rewardData, RewardedVideoAd RewardedVideoAd) =>
 0x7b;