Exemple #1
0
    void ProcessLandoltMessage(Osc.Message msg)
    {
        try {
            var json = JSON.Parse(msg.data[0].ToString());
            var data = convertToLandoltData(json);

            int landoltIndex = "/landolt".Length;
            if (msg.path.IndexOf("/create") == landoltIndex)
            {
                LandoltManager.Create(data);
            }
            else if (msg.path.IndexOf("/update") == landoltIndex)
            {
                LandoltManager.Update(data);
            }
            else if (msg.path.IndexOf("/remove") == landoltIndex)
            {
                LandoltManager.Remove(data);
            }
            else
            {
                Debug.LogWarning("unknown message: " + msg);
            }
        } catch (Exception e) {
            Debug.LogWarning(e.Message);
            Debug.LogWarning(msg);
        }
    }
Exemple #2
0
            public static SensorInput Parse(Osc.Message m)
            {
                var x = (float)m.data [0];
                var y = (float)m.data [1];
                var z = (float)m.data [2];
                var w = (float)m.data [3];
                var h = (float)m.data [4];

                return(new SensorInput(new Vector3(x, y, z), new Vector2(w, h)));
            }
Exemple #3
0
 public void UpdateText(Osc.Message msg)
 {
     stringBuilder.Length = 0;
     stringBuilder.AppendLine(debugInfo);
     if (msg.path.Contains(targetPath))
     {
         for (int i = 0; i < msg.data.Length; i++)
         {
             stringBuilder.AppendLine(msg.data[i].ToString());
         }
         text.text = stringBuilder.ToString();
     }
 }
Exemple #4
0
    void ProcessMarkerMessage(Osc.Message msg)
    {
        var json = JSON.Parse(msg.data[0].ToString());
        var data = convertToMarkerData(json);

        int markerIndex = "/marker".Length;

        if (msg.path.IndexOf("/create") == markerIndex)
        {
            MarkerManager.Create(data);
        }
        else if (msg.path.IndexOf("/update") == markerIndex)
        {
            MarkerManager.Update(data);
        }
        else if (msg.path.IndexOf("/remove") == markerIndex)
        {
            MarkerManager.Remove(data);
        }
        else
        {
            Debug.LogWarning("unknown message: " + msg);
        }
    }
Exemple #5
0
        void ReadMessage()
        {
            var path = ReadString ();

            if (path == "#bundle") {
                ReadInt64 ();

                while (true) {
                    if (readPoint >= readBuffer.Length) {
                        return;
                    }
                    var peek = readBuffer [readPoint];
                    if (peek == '/' || peek == '#') {
                        ReadMessage ();
                        return;
                    }
                    var bundleEnd = readPoint + ReadInt32 ();
                    while (readPoint < bundleEnd) {
                        ReadMessage ();
                    }
                }
            }

            var temp = new Message ();
            temp.path = path;

            var types = ReadString ();
            temp.data = new object[types.Length - 1];

            for (var i = 0; i < types.Length - 1; i++) {
                switch (types [i + 1]) {
                case 'f':
                    temp.data [i] = ReadFloat32 ();
                    break;
                case 'i':
                    temp.data [i] = ReadInt32 ();
                    break;
                case 's':
                    temp.data [i] = ReadString ();
                    break;
                case 'b':
                    temp.data [i] = ReadBlob ();
                    break;
                }
            }

            messageBuffer.Enqueue (temp);
        }
Exemple #6
0
    void Update()
    {
        if (multicast != lastMulticastSetting)
        {
            setListenPort();
        }

        if (udpClient == null)
        {
            return;
        }

        while (udpClient.Available > 0)
        {
            osc.FeedData(udpClient.Receive(ref endPoint));
        }

        while (osc.MessageCount > 0)
        {
            Osc.Message msg = osc.PopMessage();
            if (msg.path == "/touchDown")
            {
                int id = (int)msg.data[0];
                position.x = float.Parse(msg.data[1].ToString());
                position.y = float.Parse(msg.data[2].ToString());

                touches.Add(id, new touch(id, position));

                foreach (touchscreenTarget t in targets)
                {
                    t.onTouchDown(id, position);
                }
            }
            else if (msg.path == "/touchUp")
            {
                int id = (int)msg.data[0];
                position.x = float.Parse(msg.data[1].ToString());
                position.y = float.Parse(msg.data[2].ToString());

                touches.Remove(id);

                foreach (touchscreenTarget t in targets)
                {
                    t.onTouchUp(id, position);
                }
            }
            else if (msg.path == "/touchMove")
            {
                int id = (int)msg.data[0];
                position.x = float.Parse(msg.data[1].ToString());
                position.y = float.Parse(msg.data[2].ToString());
                size.x     = float.Parse(msg.data[3].ToString());
                size.y     = float.Parse(msg.data[4].ToString());

                difference.x = touches[id].position.x - position.x;
                difference.y = touches[id].position.y - position.y;

                touches[id].set(position, size);

                foreach (touchscreenTarget t in targets)
                {
                    t.onTouchRelativeMoved(id, difference);
                    t.onTouchMoved(id, position, size);
                }
            }

            if (debug)
            {
                string outstring = "";
                foreach (var v in msg.data)
                {
                    outstring += v.ToString() + "\t";
                }
                Debug.Log("OSC: " + outstring);
            }
        }
    }
 public void OnOsc(Osc.Message msg)
 {
     oscMsg = msg.ToString();
 }
 void OnMessage(Osc.Message msg)
 {
     // ここで適当に処理する
     Debug.LogFormat("{0} => {1}", msg.path, msg.data[0]);
 }