Exemplo n.º 1
0
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            OscMessage msg = (OscMessage)args.Packet;

            Globals.GlobalVar.radiusSyncValue        = (float)msg.Data[0];
            Globals.GlobalVar.OscSendRadiusSyncEvent = true;
        }
Exemplo n.º 2
0
 private void OnOSCMessageSended(object sender, UniOSCEventArgs args)
 {
     if (traceMessages)
     {
         _TraceOSCMessage(sender, args, false);
     }
 }
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            Debug.Log("Hit!");
            OscMessage msg = (OscMessage)args.Packet;

            if (msg.Data.Count < 1)
            {
                return;
            }
            //if(!( msg.Data[0]  is  System.Single))return;

            if (codeSelection == 1)
            {
                Debug.Log("Hi Bitch");
                instantiatedObjects [objectIndex] = Instantiate(userPrefab, userPrefab.transform.position, Quaternion.identity);
                Debug.Log(objectIndex);
                objectIndex = objectIndex + 1;
                Debug.Log(objectIndex);
            }
            else if (codeSelection == 2)
            {
                Debug.Log("Yo Bitch" + msg.Data [0].ToString());

                number = msg.Data [0].ToString();

                Debug.Log(number);
                instantiateOut.Trigger(number);
            }
            else if (codeSelection == 3)
            {
                Debug.Log("What up bitch?");
                number = msg.Data [0].ToString();
                ClientCubeOSC.newAddress(number);
            }
        }
Exemplo n.º 4
0
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            OscMessage msg = (OscMessage)args.Packet;

            Globals.GlobalVar.OscReportButtonValue = (int)msg.Data[0];
            Globals.GlobalVar.OscReportButtonEvent = true;
        }
        /// <summary>
        /// Method is called from a OSCConnection when a OSC message arrives.
        /// The argument is a UniOSCEventArgs object where all the related data is enclosed
        /// </summary>
        /// <param name="args">OSCEventArgs</param>
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            //this is the method where you handle the OSC data and do your stuff with the GameObject!

            //args.Address
            //args.Message
            //args.Message.Data  (get the data as an object[] array)

            //It is a good practice to always check the data count before accessing the data.
            // if(args.Message.Data.Count <1)return;

            /*to  check the data type we have several option:
             * a)
             * if(( args.Message.Data[0] is System.Single)
             *
             * b)
             * if( args.Message.Data[0].GetType() == typeof(System.Single))
             *
             * c) check the typeTag (see OSC documentation : http://opensoundcontrol.org/spec-1_0
             * typeTag is a string like ',f' for a single float or ',ff' for two floats
             * if(args.Message.TypeTag.Substring(1,1) == "f")
             */

            //Debug.Log("typeTag: "+args.Message.TypeTag);

            //For addresses like  '/1/push8'  we could filter via these properties:
            //args.Group (1)
            //args.AddressRoot ("push")
            //args.AddressIndex (8)
            //Debug.Log("Group: "+args.Group);
            //Debug.Log("AddressRoot: "+args.AddressRoot);
            //Debug.Log("AddressIndex: "+args.AddressIndex);
            //if the OSC address doesn't match this pattern the Group and AddressIndex will be default -1 and AddressRoot is empty
        }
Exemplo n.º 6
0
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            if (args.Message.Data.Count < 1)
            {
                return;
            }
            if (_mat == null)
            {
                return;
            }

            if (!(args.Message.Data[0]  is  System.Single))
            {
                return;
            }
            float value = (float)args.Message.Data[0];

            if (String.Equals(args.Address, R_Address))
            {
                _mat.color = new Color(value, _mat.color.g, _mat.color.b);
            }
            if (String.Equals(args.Address, G_Address))
            {
                _mat.color = new Color(_mat.color.r, value, _mat.color.b);
            }
            if (String.Equals(args.Address, B_Address))
            {
                _mat.color = new Color(_mat.color.r, _mat.color.g, value);
            }
        }
Exemplo n.º 7
0
 // this method is called from a different thread so we fill the queue that is later read on FixedUpdate
 private void OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     lock (_eventLock)
     {
         _eventQueue.Enqueue(args);
     }
 }
Exemplo n.º 8
0
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            if (transformToMove == null)
            {
                return;
            }
            if (args.Message.Data.Count < 1)
            {
                return;
            }

            float x = transformToMove.transform.position.x + xOffset;
            float y = transformToMove.transform.position.y + yOffset;
            float z = transformToMove.transform.position.z;

            //Debug.Log("X = "+x+"; "+"Y = "+y+"; "+"Z = "+z+";");
            //y = Screen.height * (float)args.Message.Data[0];
            y = (float)args.Message.Data[0] + yOffset;

            if (args.Message.Data.Count == 2)
            {
                //x = Screen.width* (float)args.Message.Data[1];
                x = (float)args.Message.Data[1] + xOffset;
            }

            //pos = new Vector3(x,y,0);
            pos = new Vector3(x, y, z);
            //transformToMove.transform.localPosition = Camera.main.ScreenToWorldPoint(pos);
            transformToMove.transform.position = pos;
        }
Exemplo n.º 9
0
 static void _OnOSCMessageSended(object sender, UniOSCEventArgs args)
 {
     if (_config.isOSCTracing == true)
     {
         _TraceOSCMessage(sender, args, false);
     }
 }
Exemplo n.º 10
0
        private void _TraceOSCMessage(object sender, UniOSCEventArgs args, bool oscIn)
        {
            msgMode     = oscIn ? "IN" : "OUT";
            _oscMessage = args.Message;
            _osctraceStrb.AppendLine("----Message " + msgMode + "-----");
            if (oscIn)
            {
                _osctraceStrb.AppendLine("Port:" + ((UniOSCConnection)sender).oscPort);
            }
            else
            {
                _osctraceStrb.AppendLine("Destination IP:" + ((UniOSCConnection)sender).oscOutIPAddress);
                _osctraceStrb.AppendLine("Port:" + ((UniOSCConnection)sender).oscOutPort);
            }

            _osctraceStrb.AppendLine("Address: " + _oscMessage.Address.ToString());

            if (_oscMessage.Data.Count > 0)
            {
                for (int i = 0; i < _oscMessage.Data.Count; i++)
                {
                    _osctraceStrb.AppendLine("Data: " + _oscMessage.Data[i].ToString());
                }
            }

            _oscTraceStr = _osctraceStrb.ToString();
            //autoscroll to bottom
            traceScrollpos = new Vector2(0f, Mathf.Infinity);
        }
Exemplo n.º 11
0
        // data at index [0] int objectToRotateID
        // data at index [1] int isRotating
        // data at index [2] float controllerZRotation


        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            OscMessage msg = (OscMessage)args.Packet;

            if (msg.Data.Count < 1)
            {
                return;
            }


            int isRotating = (int)msg.Data[1];

            if (isRotating == 1)
            {
                //Debug.Log("Scroll wheel is rotating");
                objectToRotateID = (int)msg.Data[0];
                if (objectToRotateID == 0)
                {
                    objectToRotate = mouseScrollableObject1;
                }
                if (objectToRotateID == 1)
                {
                    objectToRotate = mouseScrollableObject2;
                }
                if (objectToRotateID == 2)
                {
                    objectToRotate = mouseScrollableObject3;
                }

                controllerZRotation = (float)msg.Data[2];
                //Debug.Log("isTwisting = true;"+rotation);
                storeRotation = objectToRotate.eulerAngles;
                objectToRotate.eulerAngles = new Vector3(storeRotation.x, storeRotation.y, controllerZRotation);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Sends the test message.
        /// Only for testing the OSC Out connection.
        /// </summary>
        public void SendTestMessage()
        {
            OSCsharp.Data.OscMessage msg  = new OSCsharp.Data.OscMessage("/test", 1f);
            UniOSCEventArgs          args = new UniOSCEventArgs(oscOutPort, msg);

            args.IPAddress = oscOutIPAddress;
            SendOSCMessage(this, args);
        }
Exemplo n.º 13
0
 protected void _SendOSCMessage(UniOSCEventArgs args)
 {
     foreach (var c in _myOSCConnections)
     {
         if (c != null)
         {
             c.SendOSCMessage(this, args);
         }
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Maps the incoming OSC data.
 /// </summary>
 /// <param name="args">Arguments.</param>
 public void MapData(UniOSCEventArgs args)
 {
     for (int i = 0; i < args.Message.Data.Count; i++)
     {
         System.Object obj = args.Message.Data[i];
         if (obj is float)
         {
             args.Message.UpdateDataAt(i, UniOSCUtils.MapInterval((float)obj, min, max, mappingMIN, mappingMAX));
         }
     }            //for
 }
Exemplo n.º 15
0
 static void _OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     if (_config.isOSCTracing == true)
     {
         _TraceOSCMessage(sender, args, true);
     }
     if (OSCMessageReceived != null)
     {
         OSCMessageReceived(Instance, args);
     }
 }
Exemplo n.º 16
0
 private void OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     if (!_showGUI)
     {
         return;
     }
     if (traceMessages)
     {
         _TraceOSCMessage(sender, args, true);
     }
 }
Exemplo n.º 17
0
        /// <summary>
        /// Sends the session data.
        /// This is useful for updating the GUI of TouOSC for example with the last data values from incomming OSC messages.
        /// You have to add a OSC Session file to the OSCConnection to use this feature.
        /// </summary>
        public void SendSessionData()
        {
            if (!hasOSCSessionFileAttached)
            {
                return;
            }
            lock (_sessionEventLock){
                foreach (var osf in oscSessionFileObjList)
                {
                    if (osf == null)
                    {
                        continue;
                    }
                    foreach (var osi  in osf.oscSessionItemList)
                    {
                        string address = osi.address;
                        if (String.IsNullOrEmpty(address))
                        {
                            continue;
                        }
                        OSCsharp.Data.OscMessage msg = new OSCsharp.Data.OscMessage(address);
                        for (int i = 0; i < osi.data.Count; i++)
                        {
                            float number;
                            bool  result = Single.TryParse(osi.data[i], out number);
                            if (result)
                            {
                                msg.Append(number);
                                //typecheck? osi.dataTypeList[i]
                                //msg.Append(Int32.Parse(osi.data[i]));
                            }
                        }

                        UniOSCEventArgs args = new UniOSCEventArgs(oscOutPort, msg);
                        args.IPAddress = oscOutIPAddress;
                        //give a delay for proper update of TouchOSC
                        //to prevent some lack at runtime we use a queue that is dequeued on _Update()
                        //In Editor mode  we stop the running thread for a millisecond.
                        //Otherwise part of the osc messages could be lost if we send to much udp packets at the same time
                        if (Application.isPlaying)
                        {
                            _sessionEventQueue.Enqueue(args);
                        }
                        else
                        {
                            Thread.Sleep(1);
                            SendOSCMessage(this, args);
                        }
                    }    //oscSessionItemList
                }        //oscSessionFileObjList
            }            //lock
        }
        /// <summary>
        /// Maps the incoming OSC data.
        /// </summary>
        /// <param name="args">Arguments.</param>
        public void MapData(UniOSCEventArgs args)
        {
            OscMessage msg = ((OscMessage)args.Packet);

            for (int i = 0; i < msg.Data.Count; i++)
            {
                System.Object obj = msg.Data[i];
                if (obj is float)
                {
                    msg.UpdateDataAt(i, UniOSCUtils.MapInterval((float)obj, min, max, mappingMIN, mappingMAX));
                }
            }            //for
        }
Exemplo n.º 19
0
 /// <summary>
 /// A delegate which is normally called from a OSCConnection when a OSC message arrives.
 /// If the port and address matches with the OnOSCMessageReceived() method is called where you could handle the data
 /// </summary>
 /// <param name="args">The current OSCEventArgs object</param>
 private void _OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     //Debug.Log("UniOSCEventTarget._OnDispatched:"+this.name);
     if (_isDispatchAble(args.Port, args.Address))
     {
         OnOSCMessageReceived(args);
         //sent out our event so that other classes are notified
         if (OSCMessageReceived != null)
         {
             OSCMessageReceived(this, args);
         }
     }
 }
Exemplo n.º 20
0
        //our custom callback methods to handle the OSC data in our editor
        private void OnOSCMessageReceived1(object sender, UniOSCEventArgs args)
        {
            Debug.Log("OnOSCMessageReceived1:" + args.Message.Address);
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(args.Message.Address);
            foreach (var d in args.Message.Data)
            {
                sb.AppendLine(d.ToString());
            }

            oscTarget1Msg = sb.ToString();
        }
Exemplo n.º 21
0
        private void _TraceOSCMessage(object sender, UniOSCEventArgs args, bool oscIn)
        {
            msgMode = oscIn ? "IN" : "OUT";
            //_oscMessage = args.Message;
            _oscPacket = args.Packet;
            _osctraceStrb.AppendLine("----Message " + msgMode + "-----");
            if (oscIn)
            {
                _osctraceStrb.AppendLine("Port:" + ((UniOSCConnection)sender).oscPort);
            }
            else
            {
                _osctraceStrb.AppendLine("Destination IP:" + ((UniOSCConnection)sender).oscOutIPAddress);
                _osctraceStrb.AppendLine("Port:" + ((UniOSCConnection)sender).oscOutPort);
            }


            if (_oscPacket.IsBundle)
            {
                _osctraceStrb.AppendLine("Bundle:");
                foreach (var m in ((OscBundle)_oscPacket).Messages)
                {
                    _osctraceStrb.AppendLine(" Address: " + m.Address.ToString());

                    if (m.Data.Count > 0)
                    {
                        for (int i = 0; i < m.Data.Count; i++)
                        {
                            _osctraceStrb.AppendLine("  Data: " + m.Data[i].ToString());
                        }
                    }
                }                //for
            }
            else
            {
                _osctraceStrb.AppendLine("Address: " + _oscPacket.Address.ToString());

                if (((OscMessage)_oscPacket).Data.Count > 0)
                {
                    for (int i = 0; i < ((OscMessage)_oscPacket).Data.Count; i++)
                    {
                        _osctraceStrb.AppendLine("Data: " + ((OscMessage)_oscPacket).Data[i].ToString());
                    }
                }
            }


            _oscTraceStr = _osctraceStrb.ToString();
            //autoscroll to bottom
            traceScrollpos = new Vector2(0f, Mathf.Infinity);
        }
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            if (transformToMove == null)
            {
                return;
            }
            OscMessage msg = (OscMessage)args.Packet;

            if (msg.Data.Count < 1)
            {
                return;
            }

            float x = transformToMove.transform.position.x;
            float y = transformToMove.transform.position.y;
            float z = transformToMove.transform.position.z;

            switch (movementMode)
            {
            case Mode.Screen:

                y = Screen.height * (float)msg.Data[0];

                if (msg.Data.Count >= 2)
                {
                    x = Screen.width * (float)msg.Data[1];
                }

                pos = new Vector3(x, y, Camera.main.nearClipPlane + nearClipPlaneOffset);
                //pos = transformToMove.transform.position; pos[0] = x;pos[1] = y;pos[2] = Camera.main.nearClipPlane + nearClipPlaneOffset;
                transformToMove.transform.position = Camera.main.ScreenToWorldPoint(pos);

                break;

            case Mode.Relative:
                z = 0f;
                y = (float)msg.Data[0];
                if (msg.Data.Count >= 2)
                {
                    x = (float)msg.Data[1];
                }
                if (msg.Data.Count >= 3)
                {
                    z = (float)msg.Data[2];
                }

                pos = new Vector3(x, y, z);
                transformToMove.transform.position += pos;
                break;
            }
        }
 public override void OnOSCMessageReceived(UniOSCEventArgs args)
 {
     if (args.Message.Data.Count < 1)
     {
         return;
     }
     if (!(args.Message.Data[0]  is  System.Single))
     {
         return;
     }
     //Debug.Log("Monochrome message received");
     toggleState = Convert.ToBoolean(args.Message.Data[0]);
     UpdateComponentState();
 }
Exemplo n.º 24
0
        protected void _SetupOSCMessage()
        {
            if (String.IsNullOrEmpty(oscOutAddress) || !oscOutAddress.StartsWith("/"))
            {
                oscOutAddress = "/" + oscOutAddress;
            }
            if (_OSCmsg == null)
            {
                _OSCmsg = new OscMessage(oscOutAddress);
            }

            _OSCeArg           = new UniOSCEventArgs(oscOutPort, _OSCmsg);
            _OSCeArg.IPAddress = oscOutIPAddress;
        }
 public bool SendOSCMessage(object sender, UniOSCEventArgs args)
 {
     if (udpTransmitter != null)
     {
         try{
             udpTransmitter.Send(args.Packet);
             return(true);
         }catch (Exception e) {
             Debug.LogWarning(e.ToString());
             return(false);
         }
     }
     return(false);
 }
Exemplo n.º 26
0
 /// <summary>
 /// Checks if we are in learning mode an writes the OSC message address into the address property of a mapping item that is in learn mode(when user hold down the 'learn' button in the editor.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="args">UniOSCEventArgs that contains the OSC message</param>
 public void OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     if (IsLearning)
     {
         foreach (var d in oscMappingItemList)
         {
             if (d.isLearning)
             {
                 //d.address = args.Message.Address;
                 d.address = args.Address;
             }
         }        //for
     }            //if
 }
Exemplo n.º 27
0
 /// <summary>
 /// Checks if we are in learning mode an writes the OSC message address into the address property of a mapping item that is in learn mode(when user hold down the 'learn' button in the editor.
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="args">UniOSCEventArgs that contains the OSC message</param>
 public void OnOSCMessageReceived(object sender, UniOSCEventArgs args)
 {
     if (IsLearning)
     {
         foreach (var d in oscMappingItemList)
         {
             if (d.isLearning)
             {
                 d.address = args.Message.Address;
                 //d.port = args.Port;
                 //if(args.Message.Data != null) d.data = args.Message.Data[0].ToString();
             }
         }        //for
     }            //if
 }
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            OscMessage msg = (OscMessage)args.Packet;

            if (msg.Data.Count < 1)
            {
                return;
            }
            if (!(msg.Data[0]  is  System.Single))
            {
                return;
            }
            // Debug.Log("data type:" + ((OscMessage)args.Packet).TypeTag);
            toggleState = Convert.ToBoolean(msg.Data[0]);
            UpdateComponentState();
        }
Exemplo n.º 29
0
        /// <summary>
        /// Checks if we are in learning mode an writes the OSC message address into the address property of a session item that is in learn mode(when user hold down the 'learn' button in the editor.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">UniOSCEventArgs that contains the OSC message</param>
        public void OnOSCMessageReceived(object sender, UniOSCEventArgs args)
        {
            if (IsLearning)
            {
                foreach (var d in oscSessionItemList)
                {
                    if (d.isLearning)
                    {
                        //d.address = args.Message.Address;
                        d.address = args.Address;
                    }
                }
            }
            else
            {
                var _osi = (UniOSCSessionItem)oscSessionItemList.Find(osi => osi.address == args.Address);
                if (_osi == null)
                {
                    return;
                }
                OscMessage msg = (OscMessage)args.Packet;
                if (msg.Data == null)
                {
                    return;
                }
                int dc = msg.Data.Count;
                for (int i = 0; i < dc; i++)
                {
                    if (_osi.data.Count < dc)
                    {
                        _osi.data.Add(String.Empty);
                        _osi.dataTypeList.Add(String.Empty);
                    }
                    if (_osi.dataTypeList.Count < dc)
                    {
                        _osi.dataTypeList.Add(String.Empty);
                    }

                    _osi.data[i] = msg.Data[i].ToString();
                    //only once we get the type .( performance concerns)
                    if (String.IsNullOrEmpty(_osi.dataTypeList[i]))
                    {
                        _osi.dataTypeList[i] = msg.Data[i].GetType().FullName;
                    }
                } //for
            }     //else
        }
Exemplo n.º 30
0
        public override void OnOSCMessageReceived(UniOSCEventArgs args)
        {
            if (transformToScale == null)
            {
                return;
            }
            if (args.Message.Data.Count < 1)
            {
                return;
            }

            _data  = (float)args.Message.Data[0];
            _data *= scaleFactor;
            _scale.Set(_data, _data, _data);

            transformToScale.localScale = _scale;
        }