コード例 #1
0
        public void SendToUnity(UnityModuleArgs events)
        {
            string packet = FormatJSON(events);
            tic++;

            //Console.WriteLine("[Client] Sending Data: " + packet);
            writeSocket(packet);
            //Console.WriteLine("[Client] Written to socket");
        }
コード例 #2
0
        /// <summary>
        /// Takes a list of GestureEvents and concatenates them into a JSON String
        /// </summary>
        /// <param name="e">UnityModuleArgs list of GestureEvents</param>
        /// <returns>JSON string</returns>
        public string FormatJSON(UnityModuleArgs e)
        {
            int i = 0; // number of event
            string json = "{";

            foreach (GestureEvent gEvent in e.Events)
            {
                gEvent.Timestamp = tic;
                if (i > 0) // if there's more than one event in packet
                {
                    json += ",";
                }
                json += "\"e" + i + "\":";   // {"e1":
                json += gEvent.ToString();
                i++;

            }
            json += "}";

            return json;
        }