public void Reward(RewardDelegate rewardDelegate, string placementId)
    {
        if (string.IsNullOrEmpty(placementId))
        {
            rewardDelegate(new RewardResult(RewardResult.Type.LoadFailed, "FAN: Placement ID is empty"));
        }
        if (rewardedVideoAd != null)
        {
            rewardedVideoAd.Dispose();
        }
        Manager.LoadingAnimation(true);
        onRewardWatched = rewardDelegate;

        rewardedVideoAd = new RewardedVideoAd(placementId);
        rewardedVideoAd.Register(gameObject);

        rewardedVideoAd.RewardedVideoAdDidLoad          = RewardedVideoAdDidLoad;
        rewardedVideoAd.RewardedVideoAdDidFailWithError = RewardedVideoAdDidFailWithError;
        //rewardedVideoAd.RewardedVideoAdWillLogImpression
        //rewardedVideoAd.RewardedVideoAdDidClick
        rewardedVideoAd.RewardedVideoAdDidSucceed = RewardedVideoAdDidSucceed;
        rewardedVideoAd.RewardedVideoAdDidFail    = RewardedVideoAdDidFail;
        rewardedVideoAd.RewardedVideoAdDidClose   = RewardedVideoAdDidClose;

#if UNITY_ANDROID
        //rewardedVideoAd.RewardedVideoAdActivityDestroyed
#endif
        rewardedVideoAd.LoadAd();
    }
コード例 #2
0
    public void LoadRewardedAd()
    {
        if (isRewardedLoaded)
        {
            return;
        }

        if (isRewardedLoading)
        {
            return;
        }

        isRewardedLoading = true;
        isRewardedLoaded  = false;

        rewardedAd = new RewardedVideoAd(rewardedAdId);
        rewardedAd.Register(gameObject);

        rewardedAd.RewardedVideoAdDidLoad = delegate()
        {
            LoadingRewardedAdSuccessful();
        };
        rewardedAd.RewardedVideoAdDidFailWithError = delegate(string error)
        {
            LoadingRewardedAdFaild();
        };
        rewardedAd.rewardedVideoAdComplete = delegate()
        {
            RewardedAdCompleted();
        };

        rewardedAd.LoadAd();
    }
コード例 #3
0
ファイル: AdManager.cs プロジェクト: hydekyle/Cricket-Arcade
    public void LoadRewardedVideo()
    {
        statusLabel.text = "Loading rewardedVideo ad...";
        rewardedVideoAd  = new RewardedVideoAd("378297562859739_378307472858748");
        rewardedVideoAd.Register(gameObject);
        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.Show();
        };

        rewardedVideoAd.RewardedVideoAdDidFailWithError = delegate(string error)
        {
            Debug.Log("RewardedVideo ad failed to load with error: " + error);
            SetStatusOrderingWindow(false);
        };

        rewardedVideoAd.RewardedVideoAdWillLogImpression = delegate()
        {
            AdGetReward();
        };

        rewardedVideoAd.RewardedVideoAdDidClick = delegate()
        {
            AdGetReward();
        };

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

        rewardedVideoAd.RewardedVideoAdDidClose = delegate()
        {
            Debug.Log("Rewarded video ad did close.");
            didClose = true;
            SetStatusOrderingWindow(false);
        };

        if (Application.platform == RuntimePlatform.Android)
        {
            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.");
                }
            };
        }
        rewardedVideoAd.LoadAd();
    }
コード例 #4
0
        /// <summary>
        /// Create new rewarded video ad with specific id.
        /// </summary>
        protected virtual RewardedVideo CreateNewRewardedVideoAd(string rewardedId, AdPlacement placement)
        {
            if (string.IsNullOrEmpty(rewardedId))
            {
                return(null);
            }

            RewardedVideoAd newRewardedVideoAd = new RewardedVideoAd(rewardedId);

            SetupRewardedVideoEvents(newRewardedVideoAd, placement);

            newRewardedVideoAd.Register(mAdHandlerObject);

            return(new RewardedVideo(newRewardedVideoAd));
        }
コード例 #5
0
    private void RequestNewAd()
    {
        return;

        if (ad != null)
        {
            ad.Dispose();
        }
        ad = new RewardedVideoAd(Zone);
        ad.Register(listener);
        ad.RewardedVideoAdDidLoad = delegate
        {
            _loadingEvents.OnNext(value: true);
        };
        ad.RewardedVideoAdDidFailWithError = delegate
        {
            _loadingEvents.OnNext(value: false);
        };
        Loading.Value = true;
        adReady.Value = false;
        ad.LoadAd();
    }
コード例 #6
0
        /// <summary>
        /// Load a Facebook rewarded video and add the required listeners
        /// </summary>
        private void LoadRewardedVideo()
        {
            if (rewardedVideoAd != null)
            {
                rewardedVideoAd.Dispose();
            }

            rewardedVideoAd = new RewardedVideoAd(rewardedVideoId);
            rewardedVideoAd.Register(gameObject);
            rewardedVideoAd.RewardedVideoAdDidLoad += RewardedVideoLoaded;

            rewardedVideoAd.RewardedVideoAdDidFailWithError  += RewardedVideoFailed;
            rewardedVideoAd.RewardedVideoAdWillLogImpression += RewardedVideoAdWillLogImpression;
            rewardedVideoAd.RewardedVideoAdDidClick          += RewardedVideoAdDidClick;
            rewardedVideoAd.RewardedVideoAdComplete          += RewardedVideoWatched;
            rewardedVideoAd.RewardedVideoAdDidClose          += RewardedVideoAdClosed;

#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 (!rewardedVideoDidClose)
                {
                    Debug.Log("Rewarded video activity destroyed without being closed first.");
                    Debug.Log("Game should resume. User should not get a reward.");
                    RewardedVideoAdClosed();
                }
            };
#endif
            rewardedVideoAd.LoadAd();
        }
コード例 #7
0
        protected override bool DoPreLoadAd()
        {
            if (m_RewardVideoAd != null && m_RewardVideoAd.IsValid())
            {
                return(false);
            }

            if (m_RewardVideoAd == null)
            {
                m_RewardVideoAd = new RewardedVideoAd(m_Config.unitID);
                m_RewardVideoAd.Register(UIMgr.S.uiRoot.gameObject);
                m_RewardVideoAd.RewardedVideoAdDidLoad            = HandleOnAdLoaded;
                m_RewardVideoAd.RewardedVideoAdDidFailWithError  += HandleOnAdFailedToLoad;
                m_RewardVideoAd.RewardedVideoAdWillLogImpression += HandleOnAdLogImpression;
                m_RewardVideoAd.RewardedVideoAdDidClick          += HandleOnAdClick;
                m_RewardVideoAd.RewardedVideoAdDidClose          += HandleOnFBAdClose;
                m_RewardVideoAd.RewardedVideoAdComplete          += HandleOnAdComplate;
                m_RewardVideoAd.RewardedVideoAdDidSucceed        += HandleOnAdSuccess;
            }

            m_RewardVideoAd.LoadAd();

            return(true);
        }
コード例 #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("1091882857878164_1152806438452472");

        // 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
        RewardData rewardData = new RewardData
        {
            UserId   = "USER_ID",
            Currency = "REWARD_ID"
        };

#pragma warning disable 0219
        RewardedVideoAd s2sRewardedVideoAd = new RewardedVideoAd("1091882857878164_1152806438452472", 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
        private void LoadRewardedVideo()
        {
#if UNITY_ANDROID
            var videoId = GameConfig.Instance.FbAds.androidRewardedVideo.Trim();
#elif UNITY_IPHONE
            var videoId = GameConfig.Instance.FbAds.iOSRewardedVideo.Trim();
#endif
            RewardData rewardData = new RewardData();
            rewardData.UserId   = "USER_ID";
            rewardData.Currency = "REWARD_ID";

            rewardedVideoAd =
                Testing
                    ? new RewardedVideoAd("VID_HD_16_9_15S_APP_INSTALL#2025198837536206_2115449855177770", rewardData)
                    : new RewardedVideoAd(videoId, rewardData);
            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;
            });
            rewardedVideoAd.RewardedVideoAdDidFailWithError = (delegate(string error)
            {
//                Debug.Log("RewardedVideo ad failed to load with error: " + error);
            });
            rewardedVideoAd.RewardedVideoAdWillLogImpression = (delegate()
            {
//                Debug.Log("RewardedVideo ad logged impression.");
            });
            rewardedVideoAd.RewardedVideoAdDidClick = (delegate()
            {
//                Debug.Log("RewardedVideo ad clicked.");
            });

            rewardedVideoAd.RewardedVideoAdDidClose = (delegate()
            {
                didClose = true;
                if (rewardedVideoAd != null)
                {
                    rewardedVideoAd.Dispose();
                }
            });
            rewardedVideoAd.RewardedVideoAdDidSucceed = (delegate() // for finished video
            {
                GamePlay.Instance.AfterVideoAds();
            });
            rewardedVideoAd.RewardedVideoAdDidFail = (delegate() // for fail finished
            {
                GameOver.Instance.OnCancel();
            });

            rewardedVideoAd.rewardedVideoAdActivityDestroyed = (delegate()
            {
                if (!didClose)
                {
                    GameOver.Instance.OnCancel();
                }
            });
            rewardedVideoAd.LoadAd();
        }
コード例 #10
0
    void LoadRewardedVideo()
    {
        rewardedVideoAd = new RewardedVideoAd(PLACEMENT_ID);

        rewardedVideoAd.Register(gameObject);

        rewardedVideoAd.RewardedVideoAdDidLoad = delegate
        {
            PlatformInterface.instance.logger.Log("RewardedVideo ad loaded.");
            IsLoaded = true;
            didClose = false;
            //showAfterLoaded
            if (IsAdCurrentlyCalled)
            {
                Show();
            }
        };

        rewardedVideoAd.RewardedVideoAdDidFailWithError = delegate(string error)
        {
            PlatformInterface.instance.logger.Log("RewardedVideo ad failed to load with error: " + error);
            platformFacebookAds.HandleShowResult(false, error);
        };

        rewardedVideoAd.RewardedVideoAdWillLogImpression = delegate
        {
            PlatformInterface.instance.logger.Log("RewardedVideo ad logged impression.");
        };

        rewardedVideoAd.RewardedVideoAdDidClick = delegate
        {
            PlatformInterface.instance.logger.Log("RewardedVideo ad clicked.");
        };

        rewardedVideoAd.RewardedVideoAdDidSucceed = delegate
        {
            PlatformInterface.instance.logger.Log("Rewarded video ad validated by server");
            // 검증 로직 없을 때는 불리지 않는 듯 하다.
        };

        rewardedVideoAd.RewardedVideoAdDidFail = delegate
        {
            PlatformInterface.instance.logger.Log("Rewarded video ad not validated, or no response from server");
            platformFacebookAds.HandleShowResult(false, "DidFail");
        };

        rewardedVideoAd.RewardedVideoAdComplete = delegate
        {
            PlatformInterface.instance.logger.Log("Rewarded video ad completed");
            didCompleted = true;
        };

        rewardedVideoAd.RewardedVideoAdDidClose = delegate
        {
            PlatformInterface.instance.logger.Log("Rewarded video ad did close.");
            didClose = true;
            platformFacebookAds.HandleShowResult(didCompleted, "");
            rewardedVideoAd?.Dispose();
        };

        if (Application.platform == RuntimePlatform.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 = () =>
            {
                if (!didClose)
                {
                    PlatformInterface.instance.logger.Log(
                        "Rewarded video activity destroyed without being closed first.");
                    PlatformInterface.instance.logger.Log("Game should resume. User should not get a reward.");
                    platformFacebookAds.HandleShowResult(false, "ActivityDestroyed");
                }
            }
        }
        ;

        // Initiate the request to load the ad.
        rewardedVideoAd.LoadAd();
    }

    void Show()
    {
        if (IsLoaded)
        {
            didCompleted = false;
            rewardedVideoAd.Show();
            IsLoaded = false;
        }
    }

    void OnDestroy()
    {
        // Dispose of rewardedVideo ad when the scene is destroyed
        rewardedVideoAd?.Dispose();
        PlatformInterface.instance.logger.Log("RewardedVideoAdTest was destroyed!");
    }
}