Beispiel #1
0
        // Send the DDBHTTP request
        public void Send(JSONObject Item)
        {
            action_count++;
            Debug.Log(action_count);
            // This is the only time we ever create a time stamp,
            // for consistency purposes.
            DateTime stamp = DateTime.UtcNow;

            var obj = new JSONObject();

            obj["TableName"] = table_name;
            obj["Item"]      = Item;
            obj["Item"]["run_count"]["S"]    = run_count.ToString();
            obj["Item"]["action_count"]["S"] = action_count.ToString();
            obj["Item"]["session_id"]["S"]   = session_id;
            obj["Item"]["run_id"]["S"]       = run_id;
            obj["Item"][primary_key]["S"]    = generateID();
            obj["Item"]["Stamp"]["S"]        = (stamp - startTime).TotalSeconds.ToString();

            http.BuildWWWRequest(obj.ToString(), stamp);
            StartCoroutine(http.WaitForRequest(http.www, callback => {
                if (callback != null)
                {
                    //Debug.Log(callback);
                }
            }));
        }
Beispiel #2
0
    // Method for querying the data for a specific run,
    // and then moving the player along the path data
    void Scan()
    {
        var      obj = new JSONObject();
        DateTime now = DateTime.UtcNow;

        obj["TableName"]        = "unity-dynamodb-test"; //"Unity";
        obj["FilterExpression"] = "run_id = :val";
        obj["ExpressionAttributeValues"][":val"]["S"] = run_id;
        obj["ReturnConsumedCapacity"] = "TOTAL";

        Debug.Log("Query complete!");
        http.BuildWWWRequest(obj.ToString(), now);

        StartCoroutine(http.WaitForRequest(http.www, callback => {
            if (callback != null)
            {
                // Put results from callback into a JSON object
                var results = JSON.Parse(callback);
                Debug.Log(results);
                // Sort results into an Action array
                points = new Action[results["Items"].Count];
                for (int i = 0; i < results["Items"].Count; i++)
                {
                    for (int p = 0; p < results["Items"].Count; p++)
                    {
                        if (results["Items"][p]["action_count"]["S"].AsInt == i + 1)
                        {
                            string action    = results["Items"][p]["Action"]["S"].Value;
                            double time      = results["Items"][p]["Stamp"]["S"].AsDouble;
                            int action_count = results["Items"][p]["action_count"]["S"].AsInt;
                            points[i]        = new Action(action, time, action_count);
                        }
                    }
                }

                // Move player to first logged point
                //iTween.MoveTo(player, new Vector2(points[0].x, points[0].y), 1.0f);

                /*for(int i = 1; i < points.Length; i++)
                 * {
                 *  float duration = Convert.ToSingle(points[i].stamp - points[i - 1].stamp);
                 *  iTween.MoveTo(player, new Vector2(points[i].x, points[i].y), 1.0f);
                 *  new WaitForSeconds(1.0f);
                 * }*/

                // Move player along path using recursive couroutines.
                // This initial time passed in is just an initial delay.
                StartCoroutine(ExecuteAfterTime(1.0f, 0));

                //InputSimulator.SimulateKeyDown(VirtualKeyCode.RIGHT);
            }
        }));
    }