Esempio n. 1
0
        public void OnRewardedWithEngageBtn_Clicked()
        {
            var engagement = new Engagement("showRewardOrImage");

            engagement.AddParam("clickCount", ++clickCount);

            DDNA.Instance.RequestEngagement(engagement, response => {
                // Since ads must be specifically disabled, try to build image message
                // first. If that fails, then see if the ad had been disabled.
                var imageMessage = ImageMessage.Create(response);
                var rewardedAd   = RewardedAd.Create(response);

                if (imageMessage != null)
                {
                    Debug.Log("Got an image message.");
                    imageMessage.OnDidReceiveResources += () => {
                        imageMessage.Show();
                    };
                    imageMessage.FetchResources();
                }
                else if (rewardedAd != null)
                {
                    rewardedAd.Show();
                }
                else
                {
                    Debug.Log("Engage didn't return an image and prevented the ad from showing.");
                }
            }, exception => {
                Debug.Log("Engage encountered an error: " + exception.Message);
            });
        }
        ///////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////////
        private void ReactToCampaignResponse(Engagement response)
        {
            ImageMessage imageMessage = ImageMessage.Create(response);

            // Handle response
            // Check we got an engagement with a valid image message.
            if (imageMessage != null)
            {
                Debug.Log("Engage returned a valid image message.");

                // This example will show the image as soon as the background
                // and button images have been downloaded.
                imageMessage.OnDidReceiveResources += () => {
                    Debug.Log("Image Message loaded resources.");
                    imageMessage.Show();
                };

                // Add a handler for the 'dismiss' action.
                imageMessage.OnDismiss += (ImageMessage.EventArgs obj) => {
                    Debug.Log("Image Message dismissed by " + obj.ID);
                };

                // Add a handler for the 'action' action.
                imageMessage.OnAction += (ImageMessage.EventArgs obj) => {
                    Debug.Log("Image Message actioned by " + obj.ID + " with command " + obj.ActionValue);

                    // Look for specific values in the Button Action and act accordingly
                    switch (obj.ActionValue.ToUpper())
                    {
                    case "GIFT":
                        AwardGiftFromEngage(response);
                        break;

                    default:
                        break;
                    }
                };

                // Download the image message resources.
                imageMessage.FetchResources();
            }
            else
            {
                Debug.Log("Engage didn't return an image message.");
            }
        }
Esempio n. 3
0
        public void RichCheckMail()
        {
            RichMailPanelShow();

            // Iterate until Engage returns empty response
            Engagement richMailCheck = new Engagement("richMailCheck");


            DDNA.Instance.RequestEngagement(richMailCheck, (response) => {
                ImageMessage imageMessage = ImageMessage.Create(response);

                if (imageMessage != null)
                {
                    // This example will show the image as soon as the background
                    // and button images have been downloaded.
                    imageMessage.OnDidReceiveResources += () => {
                        Debug.Log("Image Message loaded resources.");
                        //imageMessage.Show();
                    };

                    // Add a handler for the 'dismiss' action.
                    imageMessage.OnDismiss += (ImageMessage.EventArgs obj) => {
                        Debug.Log("Image Message dismissed by " + obj.ID);
                    };

                    // Add a handler for the 'action' action.
                    imageMessage.OnAction += (ImageMessage.EventArgs obj) => {
                        Debug.Log("Image Message actioned by " + obj.ID + " with command " + obj.ActionValue);
                        if (obj.ActionValue == "GIFT")
                        {
                            DropCoins(100);
                        }
                    };

                    imageMessage.FetchResources();
                    RichEmailReceived(response.JSON, imageMessage);
                }
                else
                {
                    Debug.Log("No More Mail");
                }
            }, (exception) => {
                Debug.Log("Engage reported an error: " + exception.Message);
            });
        }
    void OnGUI()
    {
        GUI.skin.textField.wordWrap = true;
        GUI.skin.button.fontSize    = 32;

        int xOffset = 0;
        int yOffset = 0;

        int buttonWidth  = 350;
        int buttonHeight = 100;


        if (GUI.Button(new Rect(yOffset += 10, xOffset += 10, buttonWidth, buttonHeight), "Param Engage"))
        {
            Debug.Log("do engage stuff");

            var engagement = new Engagement("startMission")
                             .AddParam("missionID", "tutorial1");

            DDNA.Instance.RequestEngagement(engagement, (System.Collections.Generic.Dictionary <string, object> response) => {
                Debug.Log("engagement");
                foreach (System.Collections.Generic.KeyValuePair <string, object> temp in response)
                {
                    Debug.Log(temp.Key);
                }


                Debug.Log(response.Values.ToString());

                System.Collections.Generic.Dictionary <string, object> parameters = (System.Collections.Generic.Dictionary <string, object>)response["parameters"];
                if (parameters.ContainsKey("isTutorial"))
                {
                    Debug.Log("the parameter: ");
                    if (System.Convert.ToBoolean(parameters["isTutorial"]))
                    {
                        cam.backgroundColor = Color.green;
                    }
                    else
                    {
                        cam.backgroundColor = Color.red;
                    }
                    Debug.Log(parameters["isTutorial"].ToString());
                }
                else
                {
                    Debug.Log("Key not found");
                }
            });
        }
        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Image Engage"))
        {
            var engagement = new Engagement("openMenu");

            DDNA.Instance.RequestEngagement(engagement, (response) => {
                ImageMessage imageMessage = ImageMessage.Create(response);

                // Check is we got an engagement with a valid image message.
                if (imageMessage != null)
                {
                    // Download the image message resources.
                    Debug.Log("Image received");
                    imageMessage.FetchResources();
                    imageMessage.OnDidReceiveResources += () => {
                        Debug.Log("Image Message loaded resources.");
                        imageMessage.Show();
                    };
                }
                else
                {
                    Debug.Log("No image message returned");
                }
            }, (exception) => {
                Debug.Log("Engage reported an error: " + exception.Message);
            });
        }

        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Clear stored data"))
        {
            Debug.Log("User pressed clear all persistent data button");

            DDNA.Instance.ClearPersistentData();
        }

        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Record event"))
        {
            Debug.Log("Record event");

            // Build a game event with a couple of event parameters
            GameEvent optionsEvent = new GameEvent("options")
                                     .AddParam("option", "Music")
                                     .AddParam("Number", (int)1123456789)
                                     .AddParam("action", "Disabled");

            // Record the event
            DDNA.Instance.RecordEvent(optionsEvent);
        }

        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Restart SDK"))
        {
            Debug.Log("User restarts DeltaDNA SDK");
            DDNA.Instance.StopSDK();
            DDNA.Instance.StartSDK(ENVIRONMENT_KEY, COLLECT_URL, ENGAGE_URL);
        }

        if (GUI.Button(new Rect(yOffset = (buttonWidth + 20), xOffset = 10, buttonWidth, buttonHeight), "Start SmartAds"))
        {
            // Register for smartAds
            DDNASmartAds.Instance.RegisterForAds();
        }

        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Show interstitial"))
        {
            var interstitialAd = InterstitialAd.Create();
            if (interstitialAd != null)
            {
                interstitialAd.Show();
            }
        }

        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Show rewarded"))
        {
            var rewardedAd = RewardedAd.Create();
            if (rewardedAd != null)
            {
                rewardedAd.Show();
            }
        }
        if (GUI.Button(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), "Reg for notif."))
        {
            Debug.Log("(re-)register for notifications");

            //Register for ios notifications
            DDNA.Instance.IosNotifications.RegisterForPushNotifications();

            //register for android notifications
            DDNA.Instance.AndroidNotifications.RegisterForPushNotifications();
        }

        GUI.Label(new Rect(yOffset, xOffset += (buttonHeight + 10), buttonWidth, buttonHeight), feedbackText);
    }
        void OnGUI()
        {
            if (GUI.Button(new Rect(10, 20, 200, 80), "Interstitial"))
            {
                var interstitialAd = InterstitialAd.Create();
                if (interstitialAd != null)
                {
                    interstitialAd.Show();
                }
            }

            if (GUI.Button(new Rect(10, 120, 200, 80), "Interstitial with Engage"))
            {
                var engagement = new Engagement("showInterstitial");

                DDNA.Instance.RequestEngagement(engagement, response =>
                {
                    var interstitialAd = InterstitialAd.Create(response);

                    if (interstitialAd != null)     // Engagement didn't prevent ad from showing

                    {
                        interstitialAd.OnInterstitialAdOpened += () => {
                            Debug.Log("Interstitial Ad opened its ad.");
                        };

                        interstitialAd.OnInterstitialAdFailedToOpen += (reason) => {
                            Debug.Log("Interstitial Ad failed to open its ad: " + reason);
                        };

                        interstitialAd.OnInterstitialAdClosed += () => {
                            Debug.Log("Interstitial Ad closed its ad.");
                        };

                        interstitialAd.Show();
                    }
                    else
                    {
                        Debug.Log("Engage disabled the interstitial ad from showing.");
                    }
                }, exception => {
                    Debug.Log("Engage encountered an error: " + exception.Message);
                });
            }

            if (GUI.Button(new Rect(10, 320, 200, 80), "Rewarded Ad"))
            {
                var rewardedAd = RewardedAd.Create();
                if (rewardedAd != null)
                {
                    rewardedAd.Show();
                }
            }

            if (GUI.Button(new Rect(10, 420, 200, 80), "Rewarded with Engage"))
            {
                var engagement = new Engagement("showRewarded");

                DDNA.Instance.RequestEngagement(engagement, response => {
                    var rewardedAd = RewardedAd.Create(response);

                    if (rewardedAd != null)
                    {
                        rewardedAd.OnRewardedAdOpened += () => {
                            Debug.Log("Rewarded Ad opened its ad.");
                        };
                        rewardedAd.OnRewardedAdFailedToOpen += (reason) => {
                            Debug.Log("Rewarded Ad failed to open its ad: " + reason);
                        };
                        rewardedAd.OnRewardedAdClosed += (reward) => {
                            Debug.Log("Rewarded Ad closed its ad with reward: " + (reward ? "YES" : "NO"));
                        };

                        rewardedAd.Show();
                    }
                    else
                    {
                        Debug.Log("Engage disabled the rewarded ad from showing.");
                    }
                }, exception => {
                    Debug.Log("Engage encountered an error: " + exception.Message);
                });
            }

            if (GUI.Button(new Rect(10, 620, 200, 80), "Rewarded or Image"))
            {
                var engagement = new Engagement("showRewardOrImage");
                engagement.AddParam("clickCount", ++clickCount);

                DDNA.Instance.RequestEngagement(engagement, response => {
                    // Since ads must be specifically disabled, try to build image message
                    // first.  If that fails, then see if the ad had been disabled.

                    var imageMessage = ImageMessage.Create(response);
                    var rewardedAd   = RewardedAd.Create(response);

                    if (imageMessage != null)
                    {
                        Debug.Log("Got an image message.");
                        imageMessage.OnDidReceiveResources += () => {
                            imageMessage.Show();
                        };
                        imageMessage.FetchResources();
                    }
                    else if (rewardedAd != null)
                    {
                        rewardedAd.Show();
                    }
                    else
                    {
                        Debug.Log("Engage didn't return an image and prevented the ad from showing.");
                    }
                }, exception => {
                    Debug.Log("Engage encountered an error: " + exception.Message);
                });
            }

            if (GUI.Button(new Rect(10, 820, 200, 80), "New Session"))
            {
                DDNA.Instance.NewSession();
            }
        }