コード例 #1
0
        internal DDNAImpl(DDNA ddna) : base(ddna)
        {
            string eventStorePath = null;

            if (Settings.UseEventStore)
            {
                eventStorePath = Settings.EVENT_STORAGE_PATH.Replace("{persistent_path}", Application.persistentDataPath);
                if (!Utils.IsDirectoryWritable(eventStorePath))
                {
                    Logger.LogWarning("Event store path unwritable, event caching disabled.");
                    Settings.UseEventStore = false;
                }
            }

            eventStore = new EventStore(eventStorePath);
            if (Settings.UseEventStore && !eventStore.IsInitialised)
            {
                // failed to access files for some reason
                Logger.LogWarning("Failed to access event store path, event caching disabled.");
                Settings.UseEventStore = false;
                eventStore             = new EventStore(eventStorePath);
            }

            #if DDNA_SMARTADS
            // initialise SmartAds so it can register for events
            var smartAds = SmartAds.Instance;
            smartAds.transform.parent = gameObject.transform;

            EngageFactory = new EngageFactory(this, smartAds);
            #else
            EngageFactory = new EngageFactory(this, null);
            #endif
        }
コード例 #2
0
            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();
                }
            }
コード例 #3
0
        private ImageMessage(
            DDNA ddna,
            JSONObject configuration,
            string name,
            int depth,
            Engagement engagement)
        {
            this.ddna = ddna;

            gameObject = new GameObject(name, typeof(RectTransform));
            SpriteMap spriteMap = gameObject.AddComponent <SpriteMap>();

            spriteMap.Build(ddna, configuration);


            OrientationChange changer = gameObject.AddComponent <OrientationChange>();

            changer.Init(redraw);

            this.name          = name;
            this.configuration = configuration;
            this.spriteMap     = spriteMap;
            this.depth         = depth;
            this.engagement    = engagement;
            changeListener     = changer;
        }
コード例 #4
0
        internal DDNAImpl(DDNA ddna) : base(ddna)
        {
            string eventStorePath = null;

            if (Settings.UseEventStore)
            {
                eventStorePath = Settings.EVENT_STORAGE_PATH
                                 .Replace("{persistent_path}", Application.persistentDataPath);
                if (!Utils.IsDirectoryWritable(eventStorePath))
                {
                    Logger.LogWarning("Event store path unwritable, event caching disabled.");
                    Settings.UseEventStore = false;
                }
            }

            eventStore = new EventStore(eventStorePath);
            if (Settings.UseEventStore && !eventStore.IsInitialised)
            {
                // failed to access files for some reason
                Logger.LogWarning("Failed to access event store path, event caching disabled.");
                Settings.UseEventStore = false;
                eventStore             = new EventStore(eventStorePath);
            }
            engageCache = new EngageCache(Settings);
            actionStore = new ActionStore(Settings.ACTIONS_STORAGE_PATH
                                          .Replace("{persistent_path}", Application.persistentDataPath));
            ImageMessageStore     = new ImageMessageStore(ddna);
            executionCountManager = new ExecutionCountManager();

            EngageFactory = new EngageFactory(this);
        }
コード例 #5
0
        public void SetUp()
        {
            ddna = DDNA.Instance;
            ddna.Settings.UseEventStore         = false;
            ddna.Settings.BackgroundEventUpload = false;
            ddna.Awake();

            uut = new DDNAImpl(ddna);
        }
コード例 #6
0
            public void Build(DDNA ddna, JSONObject configuration)
            {
                store = ddna.GetImageMessageStore();

                try {
                    this.URL           = configuration["url"] as string;
                    this.Width         = (int)((long)configuration["width"]);
                    this.Height        = (int)((long)configuration["height"]);
                    this.configuration = configuration["spritemap"] as JSONObject;
                } catch (KeyNotFoundException exception) {
                    Logger.LogError("Invalid format: " + exception.Message);
                }
            }
コード例 #7
0
            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();
                }
            }
コード例 #8
0
ファイル: DDNAImpl.cs プロジェクト: kurtdekker/unity-sdk
        private IEnumerator PostEvents(string[] events, Action <bool, int> resultCallback)
        {
            string bulkEvent = "{\"eventList\":[" + String.Join(",", events) + "]}";
            string url;

            if (HashSecret != null)
            {
                string md5Hash = DDNA.GenerateHash(bulkEvent, this.HashSecret);
                url = DDNA.FormatURI(Settings.COLLECT_HASH_URL_PATTERN, this.CollectURL, this.EnvironmentKey, md5Hash);
            }
            else
            {
                url = DDNA.FormatURI(Settings.COLLECT_URL_PATTERN, this.CollectURL, this.EnvironmentKey, null);
            }

            int  attempts  = 0;
            bool succeeded = false;
            int  status    = 0;

            Action <int, string, string> completionHandler = (statusCode, data, error) => {
                if (statusCode > 0 && statusCode < 400)
                {
                    succeeded = true;
                }
                else
                {
                    Logger.LogDebug("Error posting events: " + error + " " + data);
                }
                status = statusCode;
            };

            HttpRequest request = new HttpRequest(url);

            request.HTTPMethod = HttpRequest.HTTPMethodType.POST;
            request.HTTPBody   = bulkEvent;
            request.setHeader("Content-Type", "application/json");

            do
            {
                yield return(StartCoroutine(Network.SendRequest(request, completionHandler)));

                if (succeeded || ++attempts < Settings.HttpRequestMaxRetries)
                {
                    break;
                }

                yield return(new WaitForSeconds(Settings.HttpRequestRetryDelaySeconds));
            } while (attempts < Settings.HttpRequestMaxRetries);

            resultCallback(succeeded, status);
        }
コード例 #9
0
        public void SetUp()
        {
            config = new Configuration()
            {
                environmentKeyDev  = "envKeyDev",
                environmentKeyLive = "envKeyLive",
                environmentKey     = 0,
                collectUrl         = "https://collectUrl",
                engageUrl          = "https://engageUrl"
            };

            uut = DDNA.Instance;
            uut.Settings.BackgroundEventUpload = false;
            uut.Awake();
        }
コード例 #10
0
ファイル: DDNAImpl.cs プロジェクト: Glaedar/deltaDNA-Task
        internal DDNAImpl(DDNA ddna) : base(ddna)
        {
            string eventStorePath = null;

            if (Settings.UseEventStore)
            {
                eventStorePath = Settings.EVENT_STORAGE_PATH
                                 .Replace("{persistent_path}", Application.persistentDataPath);
                if (!Utils.IsDirectoryWritable(eventStorePath))
                {
                    Logger.LogWarning("Event store path unwritable, event caching disabled.");
                    Settings.UseEventStore = false;
                }
            }

            eventStore = new EventStore(eventStorePath);
            if (Settings.UseEventStore && !eventStore.IsInitialised)
            {
                // failed to access files for some reason
                Logger.LogWarning("Failed to access event store path, event caching disabled.");
                Settings.UseEventStore = false;
                eventStore             = new EventStore(eventStorePath);
            }
            engageCache = new EngageCache(Settings);
            actionStore = new ActionStore(Settings.ACTIONS_STORAGE_PATH
                                          .Replace("{persistent_path}", Application.persistentDataPath));
            ImageMessageStore     = new ImageMessageStore(ddna);
            executionCountManager = new ExecutionCountManager();

            #if DDNA_SMARTADS
            // initialise SmartAds so it can register for events
            var smartAds = SmartAds.Instance.Config(engageCache);
            smartAds.transform.parent = gameObject.transform;

            EngageFactory = new EngageFactory(this, smartAds);

            Application.RequestAdvertisingIdentifierAsync(
                (string advertisingId, bool trackingEnabled, string error) => {
                if (trackingEnabled)
                {
                    PlayerPrefs.SetString(DDNA.PF_KEY_ADVERTISING_ID, advertisingId);
                }
            }
                );
            #else
            EngageFactory = new EngageFactory(this, null);
            #endif
        }
コード例 #11
0
        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);
        }
コード例 #12
0
            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);
                }
            }
コード例 #13
0
        private ImageMessage(
            DDNA ddna,
            JSONObject configuration,
            string name,
            int depth,
            Engagement engagement)
        {
            this.ddna = ddna;

            gameObject = new GameObject(name, typeof(RectTransform));
            SpriteMap spriteMap = gameObject.AddComponent <SpriteMap>();

            spriteMap.Build(ddna, configuration);

            this.configuration = configuration;
            this.spriteMap     = spriteMap;
            this.depth         = depth;
            this.engagement    = engagement;
        }
コード例 #14
0
            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();
                }
            }
コード例 #15
0
            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;
                }
            }
コード例 #16
0
 internal DDNANonTracking(DDNA ddna) : base(ddna)
 {
     EngageFactory = new EngageFactory(this, null);
 }
コード例 #17
0
        internal override void ForgetMe()
        {
            if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN))
            {
                Logger.LogDebug("Already forgotten user " + UserID);
                return;
            }

            Logger.LogDebug("Forgetting user " + UserID);
            PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1);

            if (IsUploading)
            {
                return;
            }

            string gameEvent;

            try {
                gameEvent = MiniJSON.Json.Serialize(
                    new GameEvent("ddnaForgetMe")
                    .AddParam("eventTimestamp", GetCurrentTimestamp())
                    .AddParam("eventUUID", Guid.NewGuid().ToString())
                    .AddParam("sessionID", SessionID)
                    .AddParam("userID", UserID)
                    .AddParam("eventParams", new Params()
                              .AddParam("platform", Platform)
                              .AddParam("sdkVersion", Settings.SDK_VERSION))
                    .AddParam("ddnaAdvertisingId", PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID))
                    .AsDictionary());
            } catch (Exception e) {
                Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message);
                return;
            }

            var url = (HashSecret != null)
                ? DDNA.FormatURI(
                Settings.COLLECT_HASH_URL_PATTERN,
                CollectURL,
                EnvironmentKey,
                DDNA.GenerateHash(gameEvent, HashSecret))
                : DDNA.FormatURI(
                Settings.COLLECT_URL_PATTERN,
                CollectURL,
                EnvironmentKey,
                null);

            HttpRequest request = new HttpRequest(url)
            {
                HTTPMethod = HttpRequest.HTTPMethodType.POST,
                HTTPBody   = gameEvent
            };

            request.setHeader("Content-Type", "application/json");

            StartCoroutine(Send(
                               request,
                               () => {
                Logger.LogDebug("Forgot user " + UserID);
                PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1);
            }));
        }
コード例 #18
0
        internal override void ForgetMe()
        {
            if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN))
            {
                Logger.LogDebug("Already forgotten user " + UserID);
                return;
            }

            Logger.LogDebug("Forgetting user " + UserID);
            PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1);

            if (IsUploading)
            {
                return;
            }

            var advertisingId = PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID);
            var dictionary    = new Dictionary <string, object>()
            {
                { "eventName", "ddnaForgetMe" },
                { "eventTimestamp", GetCurrentTimestamp() },
                { "eventUUID", Guid.NewGuid().ToString() },
                { "sessionID", SessionID },
                { "userID", UserID },
                { "eventParams", new Dictionary <string, object>()
                  {
                      { "platform", Platform },
                      { "sdkVersion", Settings.SDK_VERSION },
                      { "ddnaAdvertisingId", advertisingId }
                  } }
            };

            if (string.IsNullOrEmpty(advertisingId))
            {
                (dictionary["eventParams"] as Dictionary <string, object>)
                .Remove("ddnaAdvertisingId");
            }

            string json;

            try {
                json = MiniJSON.Json.Serialize(dictionary);
            } catch (Exception e) {
                Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message);
                return;
            }

            var url = (HashSecret != null)
                ? DDNA.FormatURI(
                Settings.COLLECT_HASH_URL_PATTERN.Replace("/bulk", ""),
                CollectURL,
                EnvironmentKey,
                DDNA.GenerateHash(json, HashSecret))
                : DDNA.FormatURI(
                Settings.COLLECT_URL_PATTERN.Replace("/bulk", ""),
                CollectURL,
                EnvironmentKey,
                null);

            HttpRequest request = new HttpRequest(url)
            {
                HTTPMethod = HttpRequest.HTTPMethodType.POST,
                HTTPBody   = json
            };

            request.setHeader("Content-Type", "application/json");

            StartCoroutine(Send(
                               request,
                               () => {
                Logger.LogDebug("Forgot user " + UserID);
                PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1);
            }));
        }
コード例 #19
0
ファイル: DDNABase.cs プロジェクト: deltaDNA/tutorial-playfab
 internal DDNABase()
 {
     ddna       = null;
     gameObject = null;
 }
コード例 #20
0
 public ImageMessageHandler(DDNA ddna, Action <ImageMessage> callback)
 {
     this.ddna     = ddna;
     this.callback = callback;
 }
コード例 #21
0
ファイル: DDNABase.cs プロジェクト: deltaDNA/tutorial-playfab
        internal DDNABase(DDNA ddna)
        {
            this.ddna = ddna;

            gameObject = ddna.gameObject;
        }
コード例 #22
0
 internal TransactionBuilder(DDNA ddna)
 {
     this.ddna = ddna;
 }