// Update is called once per frame
 void Update()
 {
     if (receiver.hasWaitingMessages())
     {
         OSCMessage msg = receiver.getNextMessage();
         Debug.Log(string.Format("message received: {0} {1}", msg.Address, DataToString(msg.Data)));
     }
 }
Exemple #2
0
 void Update()
 {
     if (receiver.hasWaitingMessages())
     {
         OSCMessage msg = receiver.getNextMessage();
         if (msg.Address == "/transition")
         {
             ReceiveMessages(msg.Data);
             //}else{
             //Debug.LogError("cannot receive the message.");
         }
     }
 }
    void Update()
    {
        // only processing/forwarding the last oscmessage in case data rate > frame rate
        bool       found      = false;
        OSCMessage newMessage = null;

        while (receiver.hasWaitingMessages())
        {
            newMessage = receiver.getNextMessage();
            found      = true;
            Debug.Log("message received: " + newMessage.Address);
            Debug.Log(DataToString(newMessage.Data));
        }

        if (found)
        {
            string result = newMessage.Data[0].ToString();

            updateEvent.Invoke(result);
        }
    }
Exemple #4
0
    void ProcessIncomingMessages()
    {
        while (receiver.hasWaitingMessages())
        {
            OSCMessage msg = receiver.getNextMessage();

            string args = "";
            msg.Data.ForEach((arg) => args += arg.ToString() + ", ");

            //Debug.Log("info received : " + msg.Address);
            if (compInfoMap.ContainsKey(msg.Address))
            {
                CompInfo info = compInfoMap[msg.Address];
                object   data = null;

                if (info == null)
                {
                    //Debug.LogWarning("Address not found : " + msg.Address);
                    continue;
                }


                if (info.infoType == CompInfo.InfoType.Method)
                {
                    int numParams = info.methodInfo.GetParameters().Length;
                    info.methodInfo.Invoke(info.comp, Enumerable.Repeat(Type.Missing, numParams).ToArray());
                    continue;
                }

                string typeString = info.type.ToString();

                switch (typeString)
                {
                case "System.String":
                case "System.Char":
                    data = msg.Data[0].ToString();
                    break;

                case "System.Boolean":
                    data = ((int)msg.Data[0] == 1);
                    break;

                case "System.Int32":
                case "System.Int64":
                case "System.UInt32":
                case "System.Int16":
                case "System.UInt16":
                case "System.Byte":
                case "System.SByte":
                    data = (int)msg.Data[0];
                    break;

                case "System.Double":
                case "System.Single":
                    data = getFloatArg(msg.Data[0]);
                    break;

                case "UnityEngine.Vector2":
                    data = new Vector2(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]));
                    break;

                case "UnityEngine.Vector3":
                    data = new Vector3(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2]));

                    break;

                case "UnityEngine.Quaternion":
                    data = Quaternion.Euler(new Vector3(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2])));
                    break;

                case "UnityEngine.Color":
                case "UnityEngine.Vector4":
                {
                    if (msg.Data.Count == 1)
                    {
                        data = (Color)msg.Data[0];
                    }
                    else if (msg.Data.Count >= 3)
                    {
                        data = new Color(getFloatArg(msg.Data[0]), getFloatArg(msg.Data[1]), getFloatArg(msg.Data[2]), msg.Data.Count > 3 ? getFloatArg(msg.Data[2]): 1.0f);
                    }
                }
                break;


                default:
                    if (info.type.IsEnum)
                    {
                        JSONObject enumO = new JSONObject();

                        FieldInfo[] fields = info.type.GetFields();

                        foreach (var field in fields)
                        {
                            if (field.Name.Equals("value__"))
                            {
                                continue;
                            }
                            if (field.Name == msg.Data[0].ToString())
                            {
                                //Debug.Log("Found enum " + field.Name + " > " + field.GetRawConstantValue());
                                data = field.GetRawConstantValue();
                            }
                        }
                    }
                    break;
                }

                if (data != null)
                {
                    switch (info.infoType)
                    {
                    case CompInfo.InfoType.Field:
                        info.fieldInfo.SetValue(info.comp, data);
                        break;

                    case CompInfo.InfoType.Property:
                        info.propInfo.SetValue(info.comp, data);
                        break;

                    case CompInfo.InfoType.VFX:
                    {
                        int    dotIndex = info.comp.GetType().ToString().LastIndexOf(".");
                        string compType = info.comp.GetType().ToString().Substring(Mathf.Max(dotIndex + 1, 0));
                        setVFXPropValue((info.comp as VisualEffect), info.genericInfo.type, info.genericInfo.name, data);
                    }
                    break;

                    case CompInfo.InfoType.Material:
                        /* {
                         *   int dotIndex = info.comp.GetType().ToString().LastIndexOf(".");
                         *   string compType = info.comp.GetType().ToString().Substring(Mathf.Max(dotIndex + 1, 0));
                         *   setMaterialPropValue((info.comp as VisualEffect), info.genericInfo.type, info.genericInfo.name, data);
                         * }*/
                        break;
                    }
                }
                else
                {
                    Debug.LogWarning("Type not handled : " + typeString + ", address : " + msg.Address);
                }
            }
            else
            {
                Debug.LogWarning("Property not found for address : " + msg.Address);
            }
        }
    }