public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject layout, Sprite sprite,
                              int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.sprite       = sprite;
                this.depth        = depth;
                this.layout       = layout;

                object backgroundObj;

                if (layout.TryGetValue("background", out backgroundObj))
                {
                    var background = backgroundObj as JSONObject;

                    object actionObj;
                    if ((background).TryGetValue("action", out actionObj))
                    {
                        RegisterAction((JSONObject)actionObj, "background");
                    }
                    else
                    {
                        RegisterAction();
                    }

                    CalculatePosition();
                }
                else
                {
                    RegisterAction();
                }
            }
Пример #2
0
        internal override bool Handle(EventTrigger trigger, ActionStore store)
        {
            if (trigger.GetAction() == Type())
            {
                // copy the json to avoid modifying original
                var response        = new JSONObject(trigger.GetResponse());
                var persistedParams = store.Get(trigger);

                if (persistedParams != null)
                {
                    response["parameters"] = persistedParams;
                }

                var image = ImageMessage.Create(
                    ddna,
                    new Engagement("dummy")
                {
                    JSON = response
                },
                    null);

                if (image != null && image.IsReady())
                {
                    if (persistedParams != null)
                    {
                        store.Remove(trigger);
                    }

                    callback(image);
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        public void CreateWithInvalidImageJSONReturnsNull()
        {
            var          engagement = new Engagement("testDecisionPoint");
            ImageMessage imageMessage;

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}";

            imageMessage = ImageMessage.Create(engagement);
            Assert.IsNull(imageMessage);

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}";

            imageMessage = ImageMessage.Create(engagement);
            Assert.IsNull(imageMessage);

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}";

            imageMessage = ImageMessage.Create(engagement);
            Assert.IsNull(imageMessage);

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}";

            imageMessage = ImageMessage.Create(engagement);
            Assert.IsNull(imageMessage);

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}}},\"parameters\":{\"rewardName\":\"wrench\"}}";

            imageMessage = ImageMessage.Create(engagement);
            Assert.IsNull(imageMessage);
        }
Пример #4
0
        public void CreateWithInvalidEngagementResturnsNull()
        {
            var          engagement   = new Engagement("testDecisionPoint");
            ImageMessage imageMessage = ImageMessage.Create(engagement);

            Assert.IsNull(imageMessage);
        }
Пример #5
0
        public void CreateWithEngagementWithoutImageKeyReturnsNull()
        {
            var engagement = new Engagement("testDecisionPoint");

            engagement.Raw = "{\n\t\"transactionID\": 2184799313132298240,\n\t\"trace\": {\n\t\t\"initialState\": {\n\t\t\t\"serverNow\": 1460107947856000,\n\t\t\t\"userCreated\": 1459296000000000,\n\t\t\t\"roeLimited\": false\n\t\t},\n\t\t\"engagements\": [{\n\t\t\t\"engagementID\": 4451,\n\t\t\t\"behaviour\": 0,\n\t\t\t\"silent\": false,\n\t\t\t\"enabled\": true,\n\t\t\t\"parameterCriteria\": [],\n\t\t\t\"metricCriteria\": [],\n\t\t\t\"existingVariant\": 8800,\n\t\t\t\"existingState\": null,\n\t\t\t\"existingStateTimestamp\": null,\n\t\t\t\"existingConverted\": 0,\n\t\t\t\"parameters\": {\n\t\t\t\t\"adShowSession\": true\n\t\t\t}\n\t\t}]\n\t},\n\t\"parameters\": {\n\t\t\"adShowSession\": true,\n\t\t\"adProviders\": [{\n\t\t\t\"adProvider\": \"ADMOB\",\n\t\t\t\"eCPM\": 294,\n\t\t\t\"adUnitId\": \"ca-app-pub-4857093250239318/9840016386\"\n\t\t}],\n\t\t\"adRewardedProviders\": [{\n\t\t\t\"adProvider\": \"UNITY\",\n\t\t\t\"eCPM\": 1060,\n\t\t\t\"gameId\": \"106546\",\n\t\t\t\"testMode\": false\n\t\t}, {\n\t\t\t\"adProvider\": \"ADCOLONY\",\n\t\t\t\"eCPM\": 1323,\n\t\t\t\"appId\": \"appdd80fa453e784901bc\",\n\t\t\t\"clientOptions\": \"version:1.0,store:google\",\n\t\t\t\"zoneId\": \"vzc9a5567db2d447d29a\"\n\t\t}, {\n\t\t\t\"adProvider\": \"CHARTBOOST\",\n\t\t\t\"eCPM\": 38,\n\t\t\t\"appId\": \"56e3e633da15274fc8aa6cbf\",\n\t\t\t\"appSignature\": \"a7f6e1592a33abbcc0ac1e311d0ea1f614fefe7c\",\n\t\t\t\"location\": \"Default\"\n\t\t}, {\n\t\t\t\"adProvider\": \"VUNGLE\",\n\t\t\t\"eCPM\": 4,\n\t\t\t\"appId\": \"961178606\"\n\t\t}],\n\t\t\"adFloorPrice\": 1,\n\t\t\"adMinimumInterval\": 200,\n\t\t\"adMaxPerSession\": 20,\n\t\t\"adMaxPerNetwork\": 1,\n\t\t\"adDemoteOnRequestCode\": 1\n\t}\n}";

            ImageMessage imageMessage = ImageMessage.Create(engagement);

            Assert.IsNull(imageMessage);
        }
Пример #6
0
        /// <summary>
        /// Requests an image message at a <code>decisionPoint</code>.
        /// </summary>
        /// <param name="decisionPoint">the decision point</param>
        /// <param name="parameters">an optional set of real-time parameters</param>
        /// <param name="callback">the callback to handle the result</param>
        public void RequestImageMessage(string decisionPoint, Params parameters, Action <ImageMessage> callback)
        {
            Engagement engagement = BuildEngagement(decisionPoint, parameters);

            ddna.RequestEngagement(engagement,
                                   (response) =>
            {
                callback(ImageMessage.Create(response));
            }, (exception) =>
            {
                callback(null);
            });
        }
            public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject config, int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.depth        = depth;

                object mask;

                if (config.TryGetValue("mask", out mask))
                {
                    bool      show    = true;
                    Color32[] colours = new Color32[1];
                    switch ((string)mask)
                    {
                    case "dimmed": {
                        colours[0] = new Color32(0, 0, 0, this.dimmedMaskAlpha);
                        break;
                    }

                    case "clear": {
                        colours[0] = new Color32(0, 0, 0, 0);
                        break;
                    }

                    default: {
                        // "none"
                        show = false;
                        break;
                    }
                    }

                    if (show)
                    {
                        texture = new Texture2D(1, 1, TextureFormat.ARGB32, false);
                        texture.SetPixels32(colours);
                        texture.Apply();
                    }
                }

                object actionObj;

                if (config.TryGetValue("action", out actionObj))
                {
                    RegisterAction((JSONObject)actionObj, "shim");
                }
                else
                {
                    RegisterAction();
                }
            }
        public static ImageMessage Create(DDNA ddna, Engagement engagement, JSONObject options)
        {
            if (engagement == null || engagement.JSON == null || !engagement.JSON.ContainsKey("image"))
            {
                return(null);
            }

            string name  = "DeltaDNA Image Message";
            int    depth = 0;

            if (options != null)
            {
                if (options.ContainsKey("name"))
                {
                    name = options["name"] as string;
                }

                if (options.ContainsKey("depth"))
                {
                    depth = (int)options["depth"];
                }
            }

            ImageMessage imageMessage = null;

            try{
                var configuration = engagement.JSON["image"] as JSONObject;
                if (ValidConfiguration(configuration))
                {
                    imageMessage = new ImageMessage(ddna, configuration, name, depth, engagement);
                    if (engagement.JSON.ContainsKey("parameters"))
                    {
                        imageMessage.Parameters = engagement.JSON["parameters"] as JSONObject;
                    }
                }
                else
                {
                    Logger.LogWarning("Invalid image message configuration.");
                }
            }
            catch (Exception exception) {
                Logger.LogWarning("Failed to create image message: " + exception.Message);
            }

            return(imageMessage);
        }
            public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject orientation,
                              List <Sprite> sprites, BackgroundLayer content, int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.depth        = depth;
                this.orientation  = orientation;
                this.content      = content;
                this.sprites      = sprites;

                object buttonsObj;

                if (orientation.TryGetValue("buttons", out buttonsObj))
                {
                    UpdatePositions(true);
                }
            }
            public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject layout, Texture texture, int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.texture      = texture;
                this.depth        = depth;

                object backgroundObj;

                if (layout.TryGetValue("background", out backgroundObj))
                {
                    var background = backgroundObj as JSONObject;

                    object actionObj;
                    if ((background).TryGetValue("action", out actionObj))
                    {
                        RegisterAction((JSONObject)actionObj, "background");
                    }
                    else
                    {
                        RegisterAction();
                    }

                    object rulesObj;
                    if (background.TryGetValue("cover", out rulesObj))
                    {
                        this.position = RenderAsCover((JSONObject)rulesObj);
                    }
                    else if (background.TryGetValue("contain", out rulesObj))
                    {
                        this.position = RenderAsContain((JSONObject)rulesObj);
                    }
                    else
                    {
                        Logger.LogError("Invalid layout");
                    }
                }
                else
                {
                    RegisterAction();
                }
            }
Пример #11
0
        public void OnImageMessageBtn_Clicked()
        {
            var engagement = new Engagement("testImageMessage")
                             .AddParam("userLevel", 4)
                             .AddParam("experience", 1000)
                             .AddParam("missionName", "Disco Volante");

            DDNA.Instance.RequestEngagement(engagement, (response) => {
                ImageMessage imageMessage = ImageMessage.Create(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);
                    };

                    // Download the image message resources.
                    imageMessage.FetchResources();
                }
                else
                {
                    Debug.Log("Engage didn't return an image message.");
                }
            }, (exception) => {
                Debug.Log("Engage reported an error: " + exception.Message);
            });
        }
        internal override bool Handle(EventTrigger trigger)
        {
            if (trigger.GetAction() == Type())
            {
                var image = ImageMessage.Create(
                    ddna,
                    new Engagement("dummy")
                {
                    JSON = trigger.GetResponse()
                },
                    null);

                if (image != null && image.IsReady())
                {
                    callback(image);
                    return(true);
                }
            }

            return(false);
        }
            public void Build(DDNA ddna, GameObject parent, ImageMessage imageMessage, JSONObject orientation, List <Texture> textures, BackgroundLayer content, int depth)
            {
                this.ddna         = ddna;
                this.parent       = parent;
                this.imageMessage = imageMessage;
                this.depth        = depth;

                object buttonsObj;

                if (orientation.TryGetValue("buttons", out buttonsObj))
                {
                    var buttons = buttonsObj as List <object>;
                    for (int i = 0; i < buttons.Count; ++i)
                    {
                        var    button = buttons[i] as JSONObject;
                        float  left = 0, top = 0;
                        object x, y;
                        if (button.TryGetValue("x", out x))
                        {
                            left = (int)((long)x) * content.Scale + content.Position.xMin;
                        }
                        if (button.TryGetValue("y", out y))
                        {
                            top = (int)((long)y) * content.Scale + content.Position.yMin;
                        }
                        this.positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                        object actionObj;
                        if (button.TryGetValue("action", out actionObj))
                        {
                            RegisterAction((JSONObject)actionObj, "button" + (i + 1));
                        }
                        else
                        {
                            RegisterAction();
                        }
                    }
                    this.textures = textures;
                }
            }
Пример #14
0
        public void CreateWithValidEngagement()
        {
            var engagement = new Engagement("testDecisionPoint");

            engagement.Raw = "{\"transactionID\":2184816393350012928,\"image\":{\"width\":512,\"height\":256,\"format\":\"png\",\"spritemap\":{\"background\":{\"x\":2,\"y\":38,\"width\":319,\"height\":177},\"buttons\":[{\"x\":2,\"y\":2,\"width\":160,\"height\":34},{\"x\":323,\"y\":180,\"width\":157,\"height\":35}]},\"layout\":{\"landscape\":{\"background\":{\"contain\":{\"halign\":\"center\",\"valign\":\"center\",\"left\":\"10%\",\"right\":\"10%\",\"top\":\"10%\",\"bottom\":\"10%\"},\"action\":{\"type\":\"none\",\"value\":\"\"}},\"buttons\":[{\"x\":-1,\"y\":144,\"action\":{\"type\":\"dismiss\",\"value\":\"\"}},{\"x\":160,\"y\":143,\"action\":{\"type\":\"action\",\"value\":\"reward\"}}]}},\"shim\":{\"mask\":\"dimmed\",\"action\":{\"type\":\"none\"}},\"url\":\"http://download.deltadna.net/engagements/3eef962b51f84f9ca21643ca21fb3057.png\"},\"parameters\":{\"rewardName\":\"wrench\"}}";

            Assert.IsNotNull(engagement.JSON);
            Assert.Contains("image", engagement.JSON.Keys);
            Assert.Contains("parameters", engagement.JSON.Keys);

            ImageMessage imageMessage = ImageMessage.Create(engagement);

            Assert.IsNotNull(imageMessage);

            Assert.That(!imageMessage.IsReady());
            Assert.That(!imageMessage.IsShowing());

            Assert.IsNotNull(imageMessage.Parameters);
            Assert.AreEqual(imageMessage.Parameters, new System.Collections.Generic.Dictionary <string, object>()
            {
                { "rewardName", "wrench" }
            });
        }
Пример #15
0
        public static ImageMessage Create(Engagement engagement, JSONObject options)
        {
            if (engagement == null || engagement.JSON == null || !engagement.JSON.ContainsKey("image")) return null;

            string name = "Image Message";
            int depth = 0;

            if (options != null) {
                if (options.ContainsKey("name")) {
                    name = options["name"] as string;
                }
                if (options.ContainsKey("depth")) {
                    depth = (int)options["depth"];
                }
            }

            ImageMessage imageMessage = null;

            try {
                var configuration = engagement.JSON["image"] as JSONObject;
                if (ValidConfiguration(configuration)) {
                    imageMessage = new ImageMessage(configuration, name, depth);
                    if (engagement.JSON.ContainsKey("parameters")) {
                        imageMessage.Parameters = engagement.JSON["parameters"] as JSONObject;
                    }
                } else {
                    Logger.LogWarning("Invalid image message configuration.");
                }
            } catch (Exception exception) {
                Logger.LogWarning("Failed to create image message: "+exception.Message);
            }

            return imageMessage;
        }
Пример #16
0
            public void Build(ImageMessage imageMessage, JSONObject config, int depth)
            {
                this.imageMessage = imageMessage;
                this.depth = depth;

                object mask;
                if (config.TryGetValue("mask", out mask)) {
                    bool show = true;
                    Color32[] colours = new Color32[1];
                    switch ((string)mask)
                    {
                        case "dimmed": {
                            colours[0] = new Color32(0, 0, 0, this.dimmedMaskAlpha);
                            break;
                        }
                        case "clear": {
                            colours[0] = new Color32(0, 0, 0, 0);
                            break;
                        }
                        default: {  // "none"
                            show = false;
                            break;
                        }
                    }
                    if (show) {
                        this.texture = new Texture2D(1, 1);
                        this.texture.SetPixels32(colours);
                        this.texture.Apply();
                    }
                }

                object actionObj;
                if (config.TryGetValue("action", out actionObj)) {
                    RegisterAction((JSONObject)actionObj, "shim");
                }
                else {
                    RegisterAction();
                }
            }
Пример #17
0
            public void Build(ImageMessage imageMessage, JSONObject orientation, List<Texture> textures, BackgroundLayer content, int depth)
            {
                this.imageMessage = imageMessage;
                this.depth = depth;

                object buttonsObj;
                if (orientation.TryGetValue("buttons", out buttonsObj)) {
                    var buttons = buttonsObj as List<object>;
                    for (int i = 0; i < buttons.Count; ++i) {
                        var button = buttons[i] as JSONObject;
                        float left = 0, top = 0;
                        object x, y;
                        if (button.TryGetValue("x", out x)) {
                            left = (int)((long)x) * content.Scale + content.Position.xMin;
                        }
                        if (button.TryGetValue("y", out y)) {
                            top = (int)((long)y) * content.Scale + content.Position.yMin;
                        }
                        this.positions.Add(new Rect(left, top, textures[i].width * content.Scale, textures[i].height * content.Scale));

                        object actionObj;
                        if (button.TryGetValue("action", out actionObj)) {
                            RegisterAction((JSONObject)actionObj, "button"+(i+1));
                        }
                        else {
                            RegisterAction();
                        }
                    }
                    this.textures = textures;
                }
            }
Пример #18
0
            public void Build(ImageMessage imageMessage, JSONObject layout, Texture texture, int depth)
            {
                this.imageMessage = imageMessage;
                this.texture = texture;
                this.depth = depth;

                object backgroundObj;
                if (layout.TryGetValue("background", out backgroundObj)) {
                    var background = backgroundObj as JSONObject;

                    object actionObj;
                    if ((background).TryGetValue("action", out actionObj)) {
                        RegisterAction((JSONObject)actionObj, "background");
                    }
                    else {
                        RegisterAction();
                    }

                    object rulesObj;
                    if (background.TryGetValue("cover", out rulesObj)) {
                        this.position = RenderAsCover((JSONObject)rulesObj);
                    }
                    else if (background.TryGetValue("contain", out rulesObj)) {
                        this.position = RenderAsContain((JSONObject)rulesObj);
                    }
                    else {
                        Logger.LogError("Invalid layout");
                    }
                }
                else {
                    RegisterAction();
                }
            }
Пример #19
0
        void OnGUI()
        {
            int x      = 10;
            int y      = 10;
            int width  = 180;
            int height = 70;
            int space  = height + 5;

            GUI.skin.textField.wordWrap = true;
            GUI.skin.button.fontSize    = 18;

            if (GUI.Button(new Rect(x, y, width, height), "Simple Event"))
            {
                GameEvent gameEvent = new GameEvent("options")
                                      .AddParam("option", "sword")
                                      .AddParam("action", "sell");

                DDNA.Instance.RecordEvent(gameEvent);
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Achievement Event"))
            {
                GameEvent gameEvent = new GameEvent("achievement")
                                      .AddParam("achievementName", "Sunday Showdown Tournament Win")
                                      .AddParam("achievementID", "SS-2014-03-02-01")
                                      .AddParam("reward", new Params()
                                                .AddParam("rewardName", "Medal")
                                                .AddParam("rewardProducts", new Product()
                                                          .AddVirtualCurrency("VIP Points", "GRIND", 20)
                                                          .AddItem("Sunday Showdown Medal", "Victory Badge", 1)
                                                          )
                                                );

                DDNA.Instance.RecordEvent(gameEvent);
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Transaction Event"))
            {
                Transaction transaction = new Transaction(
                    "Weapon type 11 manual repair",
                    "PURCHASE",
                    new Product()
                    .AddItem("WeaponsMaxConditionRepair:11", "WeaponMaxConditionRepair", 5)
                    .AddVirtualCurrency("Credit", "PREMIUM", 710),
                    new Product().SetRealCurrency("USD", Product.ConvertCurrency("USD", 12.34m))) // $12.34
                                          .SetTransactorId("2.212.91.84:15116")
                                          .SetProductId("4019")
                                          .AddParam("paymentCountry", "GB");

                DDNA.Instance.RecordEvent(transaction);
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Engagement"))
            {
                var engagement = new Engagement("gameLoaded")
                                 .AddParam("userLevel", 4)
                                 .AddParam("experience", 1000)
                                 .AddParam("missionName", "Disco Volante");

                DDNA.Instance.RequestEngagement(engagement, (Dictionary <string, object> response) =>
                {
                    popupContent = DeltaDNA.MiniJSON.Json.Serialize(response);
                });

                popupTitle = "Engage returned";
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Image Message"))
            {
                var engagement = new Engagement("imageMessage")
                                 .AddParam("userLevel", 4)
                                 .AddParam("experience", 1000)
                                 .AddParam("missionName", "Disco Volante");

                DDNA.Instance.RequestEngagement(engagement, (response) => {
                    ImageMessage imageMessage = ImageMessage.Create(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);
                        };

                        // Download the image message resources.
                        imageMessage.FetchResources();
                    }
                    else
                    {
                        Debug.Log("Engage didn't return an image message.");
                    }
                }, (exception) => {
                    Debug.Log("Engage reported an error: " + exception.Message);
                });
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Notification Opened"))
            {
                var payload = new Dictionary <string, object>();
                payload.Add("_ddId", 1);
                payload.Add("_ddName", "Example Notification");
                payload.Add("_ddLaunch", true);
                DDNA.Instance.RecordPushNotification(payload);
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Upload Events"))
            {
                DDNA.Instance.Upload();
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Start SDK"))
            {
                DDNA.Instance.StartSDK(ENVIRONMENT_KEY, COLLECT_URL, ENGAGE_URL);
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "Stop SDK"))
            {
                DDNA.Instance.StopSDK();
            }

            if (GUI.Button(new Rect(x, y += space, width, height), "New Session"))
            {
                DDNA.Instance.NewSession();
            }

            if (popupContent != "")
            {
                GUI.ModalWindow(0, new Rect(Screen.width / 2 - 150, Screen.height / 2 - 100, 300, 200), RenderPopupContent, popupTitle);
            }
        }
Пример #20
0
        public void CreateWithNullEngagementReturnsNull()
        {
            ImageMessage imageMessage = ImageMessage.Create(null);

            Assert.IsNull(imageMessage);
        }