public void OnDisable() { //Debug.Log("OnDisable"); EditorApplication.playmodeStateChanged -= _HandleOnPlayModeChanged; if (OSCConnection == null) { return; } oscTarget1.Dispose(); oscTarget1 = null; oscTarget2.Dispose(); oscTarget2 = null; oscTarget3.Dispose(); oscTarget3 = null; oscTarget4.Dispose(); oscTarget4 = null; oscTarget5.Dispose(); oscTarget5 = null; oscSender1.Dispose(); oscSender1 = null; }
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(); }