Ejemplo n.º 1
0
    public static AcceleratorData fromIosSerialised(JObject serialised)
    {
        /*{
         *  "y" : -0.164306640625,
         *  "z" : 1.021728515625,
         *  "device_id" : "6DB79342-CE9F-D01A-CA42-175A006E5F15",
         *  "when" : "NOT_IMPLEMENTED",
         *  "x" : -0.113525390625
         * }*/
        var self = new AcceleratorData();

        self.xAcceleration = serialised["x"].Value <float>();
        self.yAcceleration = serialised["y"].Value <float>();
        self.zAcceleration = serialised["z"].Value <float>();
        self.deviceId      = serialised["device_id"].Value <string>();
        var dateString = serialised["when"].Value <string>();

        self.when = DateTimeExt.fromiOSDate(dateString);
        return(self);
    }
    private static void ProcessIosMessage(string subject, string content)
    {
        var isAboutDevicesFound = subject == MessageSubjects.foundNewDevices || subject == MessageSubjects.foundKnownDevices;

        if (isAboutDevicesFound)
        {
            var devices     = new List <DeviceCard>();
            var jsonContent = JObject.Parse(content);
            var jsonData    = jsonContent["data"] as JArray;

            var anything = jsonData.First;
            //print("ehmmm.... [" + anything.GetType() + "]: " + anything);
            foreach (var thingie in jsonData)
            {
                devices.Add(DeviceCard.fromIosSerialised(thingie as JObject));
            }
            print("deserialised " + devices.Count + " cards at ProcessIosMessage<" + subject + ">");
            if (subject == MessageSubjects.foundNewDevices)
            {
                onNewDevicesScaned?.Invoke(devices);
            }
            else if (subject == MessageSubjects.foundKnownDevices)
            {
                onKnowDevicesScaned?.Invoke(devices);
            }
        }
        else if (subject == MessageSubjects.acceleratorData)
        {
            print("HAVE DATA FROM ACCELEROMETER: " + content);
            var jContent = JObject.Parse(content);
            print("it is: " + jContent);
            var translated = AcceleratorData.fromIosSerialised(jContent);
            print("so finally we have model: " + translated);
        }
        else
        {
            print(">>> got [" + subject + "] message from iOS inside unity: \n   " + content);
        }
    }