Exemplo n.º 1
0
 private void OnRewardedAdOpened(RewardedAd ad)
 {
     if (ad == rewardedAd1)
     {
         rewarded1Btn.interactable = false;
         rewarded1Msg.text         = "Fulfilled";
     }
     else if (ad == rewardedAd2)
     {
         rewarded2Btn.interactable = false;
         rewarded2Msg.text         = "Fulfilled";
     }
 }
Exemplo n.º 2
0
 private void OnRewardedAdFailedToOpen(RewardedAd ad, string reason)
 {
     if (ad == rewardedAd1)
     {
         rewarded1Btn.interactable = false;
         rewarded1Msg.text         = "Failed to open; " + reason;
     }
     else if (ad == rewardedAd2)
     {
         rewarded2Btn.interactable = false;
         rewarded2Msg.text         = "Failed to open; " + reason;
     }
 }
Exemplo n.º 3
0
 private void OnRewardedAdLoaded(RewardedAd ad)
 {
     if (ad == rewardedAd1)
     {
         rewarded1Btn.interactable = true;
         rewarded1Msg.text         = "Ready";
     }
     else if (ad == rewardedAd2)
     {
         rewarded2Btn.interactable = true;
         rewarded2Msg.text         = "Ready";
     }
 }
Exemplo n.º 4
0
        private void OnRewardedAdClosed(RewardedAd ad, bool completed)
        {
            var msg = completed
                ? string.Format(
                "Watched, reward player {0} {1}",
                ad.RewardAmount,
                ad.RewardType)
                : "Skipped, don't reward player";

            if (ad == rewardedAd1)
            {
                rewarded1Btn.interactable = false;
                rewarded1Msg.text         = msg;
            }
            else if (ad == rewardedAd2)
            {
                rewarded2Btn.interactable = false;
                rewarded2Msg.text         = msg;
            }
        }
Exemplo n.º 5
0
        // Use this for initialization
        void Start()
        {
            var buttons = FindObjectsOfType <Button>().ToList();

            interstitialBtn = buttons.Find(e => e.name == "Interstitial Btn");
            rewarded1Btn    = buttons.Find(e => e.name == "Rewarded1 Btn");
            rewarded2Btn    = buttons.Find(e => e.name == "Rewarded2 Btn");

            var texts = FindObjectsOfType <Text>().ToList();

            interstitialMsg   = texts.Find(e => e.name == "Interstitial Msg");
            interstitialStats = texts.Find(e => e.name == "Interstitial Stats");
            rewarded1Msg      = texts.Find(e => e.name == "Rewarded1 Msg");
            rewarded1Stats    = texts.Find(e => e.name == "Rewarded1 Stats");
            rewarded2Msg      = texts.Find(e => e.name == "Rewarded2 Msg");
            rewarded2Stats    = texts.Find(e => e.name == "Rewarded2 Stats");

            // Configure the SDK
            DDNA.Instance.SetLoggingLevel(Logger.Level.DEBUG);

            // Setup Ad notifications
            SmartAds.Instance.OnDidRegisterForInterstitialAds += () => {
                Debug.Log("Registered for interstitial ads.");

                DDNA.Instance.EngageFactory.RequestInterstitialAd(
                    "interstitialAd",
                    (action => {
                    interstitialAd = action;
                    interstitialAd.OnInterstitialAdOpened += OnInterstitialAdOpened;
                    interstitialAd.OnInterstitialAdFailedToOpen += OnInterstitialAdFailedToOpen;
                    interstitialAd.OnInterstitialAdClosed += OnInterstitialAdClosed;

                    interstitialBtn.interactable = true;
                    interstitialMsg.text = "Ready";
                }));
            };
            SmartAds.Instance.OnDidFailToRegisterForInterstitialAds += (string reason) => {
                Debug.Log("Failed to register for interstitial ads, " + reason);

                interstitialMsg.text         = "Failed to register for interstitial ads";
                interstitialBtn.interactable = false;
                interstitialAd = null;
            };
            SmartAds.Instance.OnDidRegisterForRewardedAds += () => {
                Debug.Log("Registered for rewarded ads.");

                DDNA.Instance.EngageFactory.RequestRewardedAd(
                    "rewardedAd1",
                    (action => {
                    rewardedAd1 = action;
                    rewardedAd1.OnRewardedAdLoaded += OnRewardedAdLoaded;
                    rewardedAd1.OnRewardedAdExpired += OnRewardedAdExpired;
                    rewardedAd1.OnRewardedAdOpened += OnRewardedAdOpened;
                    rewardedAd1.OnRewardedAdFailedToOpen += OnRewardedAdFailedToOpen;
                    rewardedAd1.OnRewardedAdClosed += OnRewardedAdClosed;

                    rewarded1Btn.interactable = true;
                    rewarded1Msg.text = "Ready";
                }));
                DDNA.Instance.EngageFactory.RequestRewardedAd(
                    "rewardedAd2",
                    (action => {
                    rewardedAd2 = action;
                    rewardedAd2.OnRewardedAdLoaded += OnRewardedAdLoaded;
                    rewardedAd2.OnRewardedAdExpired += OnRewardedAdExpired;
                    rewardedAd2.OnRewardedAdOpened += OnRewardedAdOpened;
                    rewardedAd2.OnRewardedAdFailedToOpen += OnRewardedAdFailedToOpen;
                    rewardedAd2.OnRewardedAdClosed += OnRewardedAdClosed;

                    rewarded2Btn.interactable = true;
                    rewarded2Msg.text = "Ready";
                }));
            };
            SmartAds.Instance.OnDidFailToRegisterForRewardedAds += (string reason) => {
                Debug.Log("Failed to register for rewarded ads, " + reason);

                rewarded1Btn.interactable = false;
                rewarded2Btn.interactable = false;
                rewarded1Msg.text         = "Failed to register for rewarded ads";
                rewarded2Msg.text         = "Failed to register for rewarded ads";

                rewardedAd1 = null;
                rewardedAd2 = null;
            };

            // Start the SDK. We recommend using the configuration UI for setting your game's
            // keys and calling StartSDK() or StartSDK(userID) instead.
            DDNA.Instance.StartSDK(new Configuration()
            {
                environmentKeyDev     = "76410301326725846610230818914037",
                environmentKey        = 0,
                collectUrl            = "https://collect2470ntysd.deltadna.net/collect/api",
                engageUrl             = "https://engage2470ntysd.deltadna.net",
                useApplicationVersion = true
            });
        }