public void OnEnable()
        {
            //	Debug.Log("OnEnable");

            // We need to monitor the playmodeStateChanged event to update the references to OSCConnections (only necessary when we use the explicitConnection feature)
            //and force a new connection setup through disable/enable on our OSCEventTargets otherwise we have to re-open our Editor
            EditorApplication.playmodeStateChanged += _HandleOnPlayModeChanged;

            //Here we show the different possibilities to create a OSCEventTarget from code:

            //When we only specify a port we listen to all OSCmessages on that port (We assume that there is a OSCConnection with that listening port in our scene)
            oscTarget1 = new UniOSCEventTargetCBImplementation(OSCPort);
            oscTarget1.OSCMessageReceived += OnOSCMessageReceived1;
            oscTarget1.Enable();

            //When we use a OSCConnection in the constructor of a OSCEventTarget instance we need to also store the InstanceID to be able to re-reference it on playmodeStateChanges!
            OSCConnection = FindObjectOfType <UniOSCConnection>() as UniOSCConnection;
            if (OSCConnection != null)
            {
                OSCConnectionID = OSCConnection.GetInstanceID();
            }

            //This implies that we use the explicitConnection mode. (With responding to all OSCmessages)
            oscTarget2 = new UniOSCEventTargetCBImplementation(OSCConnection);
            oscTarget2.OSCMessageReceived += OnOSCMessageReceived2;
            oscTarget2.Enable();

            //We listen to a special OSCAddress regardless of the port.
            oscTarget3 = new UniOSCEventTargetCBImplementation(OSCAddress);
            oscTarget3.OSCMessageReceived += OnOSCMessageReceived3;
            oscTarget3.Enable();

            //The standard : respond to a given OSCAddress on a given port
            oscTarget4 = new UniOSCEventTargetCBImplementation(OSCAddress, OSCPort);
            oscTarget4.OSCMessageReceived += OnOSCMessageReceived4;
            oscTarget4.Enable();

            //This version has the advantage that we are not bound to a special port. If the connection changes the port we still respond to the OSCMessage
            oscTarget5 = new UniOSCEventTargetCBImplementation(OSCAddress, OSCConnection);
            oscTarget5.OSCMessageReceived += OnOSCMessageReceived5;
            oscTarget5.Enable();

            oscSender1 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress, OSCConnection);
            oscSender1.AppendData("TestData");
            oscSender1.AppendData(12345);
            oscSender1.Enable();
        }
Example #2
0
        void OnGUI()
        {
            GUILayout.Label("OSC GUI Labels", EditorStyles.boldLabel);
            pageLabel1 = EditorGUILayout.TextField("Page 1", pageLabel1);
            pageLabel2 = EditorGUILayout.TextField("Page 2", pageLabel2);
            pageLabel3 = EditorGUILayout.TextField("Page 3", pageLabel3);
            pageLabel4 = EditorGUILayout.TextField("Page 4", pageLabel4);
            pageLabel5 = EditorGUILayout.TextField("Page 5", pageLabel5);

            //groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
            //myBool = EditorGUILayout.Toggle ("Toggle", myBool);
            //myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
            //EditorGUILayout.EndToggleGroup ();

            if (GUILayout.Button(new GUIContent("Send Data", "Send Data"), GUILayout.MinHeight(30)))
            {
                Debug.Log("OnOSCMessageSend All");
                oscSender1.ClearData();
                oscSender1.AppendData(pageLabel1);
                oscSender1.Enable();
                oscSender1.SendOSCMessage();

                oscSender2.ClearData();
                oscSender2.AppendData(pageLabel2);
                oscSender2.Enable();
                oscSender2.SendOSCMessage();

                oscSender3.ClearData();
                oscSender3.AppendData(pageLabel3);
                oscSender3.Enable();
                oscSender3.SendOSCMessage();

                oscSender4.ClearData();
                oscSender4.AppendData(pageLabel4);
                oscSender4.Enable();
                oscSender4.SendOSCMessage();

                oscSender5.ClearData();
                oscSender5.AppendData(pageLabel5);
                oscSender5.Enable();
                oscSender5.SendOSCMessage();
            }

            //GUILayout.Space(10);
            //GUILayout.Label("oscTarget1 OSC IN Message:");
            //GUILayout.Label(oscTarget1Msg);
        }
Example #3
0
        public void OnEnable()
        {
            //	Debug.Log("OnEnable");

            // We need to monitor the playmodeStateChanged event to update the references to OSCConnections (only necessary when we use the explicitConnection feature)
            //and force a new connection setup through disable/enable on our OSCEventTargets otherwise we have to re-open our Editor
            EditorApplication.playmodeStateChanged += _HandleOnPlayModeChanged;


            //When we use a OSCConnection in the constructor of a OSCEventTarget instance we need to also store the InstanceID to be able to re-reference it on playmodeStateChanges!



            OSCConnection = FindObjectOfType <UniOSCConnection>() as UniOSCConnection;

            // list of all connections
            //_myOSCConnections



            if (OSCConnection != null)
            {
                OSCConnectionID = OSCConnection.GetInstanceID();
                //Debug.Log(OSCConnection.GetInstanceID());

                //int numberOfConnections = FindObjectsOfTypeAll(typeof(UniOSCConnection)).Length;


                //L[] numberOfConnections = FindObjectsOfType(typeof(UniOSCConnection)) as UniOSCConnection[];

//				Debug.Log("IP: "+OSCConnection.oscOutIPAddress+" Port:"+OSCConnection.oscOutPort+" Instance ID: "+OSCConnection.GetInstanceID);
                Debug.Log("OSC Connections:" + _myOSCConnections.Count);

                //public UniOSCEventDispatcherCBImplementation(string _oscOutAddress, string _oscOutIPAddress, int _oscPort): base( _oscOutAddress, _oscOutIPAddress, _oscPort)
                //oscSender1 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress1,"10.0.1.10", 9000);
                oscSender1 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress1, OSCConnection);
                oscSender1.AppendData(pageLabel1);
                //oscSender1.AppendData(pageLabel1);
                //oscSender1.AppendData(pageLabel1);
                oscSender1.Enable();


                //oscSender2 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress2,"10.0.1.10", 9000);
                oscSender2 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress2, OSCConnection);
                oscSender2.AppendData(pageLabel2);
                //oscSender1.AppendData("b");
                oscSender2.Enable();


                //	oscSender3 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress3,"10.0.1.10", 9000);
                oscSender3 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress3, OSCConnection);
                oscSender3.AppendData(pageLabel3);
                //oscSender1.AppendData("b");
                oscSender3.Enable();


                //oscSender4 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress4,"10.0.1.10", 9000);
                oscSender4 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress4, OSCConnection);
                oscSender4.AppendData(pageLabel4);
                //oscSender1.AppendData("b");
                oscSender4.Enable();


                //oscSender5 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress5,"10.0.1.10", 9000);
                oscSender5 = new UniOSCEventDispatcherCBImplementation(OSCOutAddress5, OSCConnection);
                oscSender5.AppendData(pageLabel5);
                //oscSender1.AppendData("b");
                oscSender5.Enable();
            }
        }