///////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////////
        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.");
            }
        }
Exemplo n.º 2
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);
    }