Public function Example1(oscMessage : OscMessage) : voidĭebug.Log("Called Example One > " + Osc.OscMessageToString(oscMessage)) ĭebug.Log("Message Values > " + oscMessage.Values) oscMessage.Values, oscMessage.Values, etc These functions are called when messages are received Handler.SetAddressHandler("/head_pos_screen", Example1) Udp.init(RemoteIP, SendToPort, ListenerPort) Var udp : UDPPacketIO = GetComponent("UDPPacketIO") make sure this game object has both UDPPackIO and OSC script attached Initializes on start up to listen for messages Public var RemoteIP : String = "127.0.0.1" You can set these variables in the scene because they are public Can't seem to get the second and third :/ In different situations you would want more involved dispatching mechanism, but not in my project.Ĭalled Example One > /head_pos_screen 431.3883 295.0804 2068.547 It also assumes that there isn't much OSC traffic besides "/spectrum". It assumes a particular format "/spectrum" messages arrive in. Yet another example shows how to deal with data that the SCClient broadcasts: Assets/SpectrumParser.cs manually informing the client of address / Port unity listens to). When working with other OSC clients you would go differently about this step (e.g. The SCClient implements communication with SuperCollider: when it starts, it sends ("/notify" 1) message, so that super collider knows to send notifications to it over the same socket. There is a separate project that implements UDP transport with an asynchronous listener: Assets/SCClient.cs The library itself only does package parsing / construction: you would probably have to adjust the OSCmessages being listened for, hardcoded around lines 20-30 of the OSCreciever script.)įYI, I have an alternative minimal implementation of OSC (only i/f/s types and no bundles supported). (attached is my modified version of dpentecost's example, configured for 4 players to move a sphere in 2 dimensions, each player using his/her iOS/android phone running an OSC app as controller. Would anyone please be able provide some advice or example code? However, I have zero experience with OO programming and have no idea how to do this. I imagine this involves running the OSC.cs plugin multiple times with each instance listening on a different port. It would be much more flexible to have player1 sending to port 1000, player2 to port 2000, and so on. player1/up, /player2/left) but this is far from ideal The problem is that with only one OSCreciever thread it is listening for OSC messages only on one port.Īs a workaround, I currently have each different player sending different OSCmessages to the same port (i.e. This is a very useful thread, I have been able to modify dpentecost's example (thankyou dpentecost!!) into a proof of concept example for controlling a multiplayer game running on a laptop/iPad via iOS/android phones as separate controllers I guess the GC cannot resolve the cyclic reference.Īll this would not be a problem, if there would be a stop method for the GameObject (that is called when the game is stopped in the editor) - then we could clean up properly. Otherwise the solution above will not work at all because the destructor is never called. I just realized one more thing: the c# callback function to be used with oscHandler.SetAddressHandler() should be declared static. To test with the example code above, I can also recommend the (osc.M monitor or OSCMonitor - on Windows platforms). This will ensure that the thread can be terminated normally (when pressing stop) and the socket can be freed. The udp listener thread in Osc.cs should be a foreground thread (set ReadThread.IsBackground=false in Osc.init). The starter script needs to implement an object destructor that calls the function oscHandler.Cancel()Ģ. To workaround these problems, I found the following solution (I can also post the C# script here if anyone is interested):ġ. This will give also strange timeouts when pressing play a second time - having to wait for some seconds until the game really starts. The udp port is not freed when restarting the game (play-stop-play). The udp listener thread is not stopping and continues to run even when the game is stoppedĢ. I implemented a C# starter script instead of the javascript one. Click to expand.Thank you very much for this example.
0 Comments
Leave a Reply. |