예제 #1
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;

            //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();
        }
예제 #2
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();
            }
        }