GMU:Tutorials/Networking/Controlling Unity with Processing: Difference between revisions

From Medien Wiki
m (→‎Processing: formatting)
m (→‎Unity: formatting)
Line 73: Line 73:
<br>
<br>


Public values are adjustable without any coding; just use the inspector for that. <br><code>
Public values are adjustable without any coding; just use the inspector for that. <br>
public var RemoteIP : String = "";<br>
<source lang="javascript">
public var SendToPort : int = xxxx;<br>
public var RemoteIP : String = "";
public var ListenerPort : int = yyyy;<br>
public var SendToPort : int = xxxx;
public var controller : Transform;<br>
public var ListenerPort : int = yyyy;
public var gameReceiver = "Cube";</code> <br><br>
public var controller : Transform;
In the Start() function all the necessary scripts and components are connected. This will happen once you press Play. <br><code>
public var gameReceiver = "Cube";
public function Start ()<br>
</source>
{<br>
In the Start() function all the necessary scripts and components are connected. This will happen once you press Play. <br>
var udp : UDPPacketIO = GetComponent("UDPPacketIO");<br>
<source lang="javascript">
udp.init(RemoteIP, SendToPort, ListenerPort);<br>
public function Start ()
handler = GetComponent("Osc");<br>
{
handler.init(udp);<br>
var udp : UDPPacketIO = GetComponent("UDPPacketIO");
handler.SetAllMessageHandler(AllMessageHandler);<br>
udp.init(RemoteIP, SendToPort, ListenerPort);
}</code> <br><br>
handler = GetComponent("Osc");
The AllMessageHandler() function is where the Osc happens. This function unpacks the Osc signals, so you can address them in other functions. In this function you can command, whenever A happens, you want FunctionB() to be executed. <br><code>
handler.init(udp);
public function AllMessageHandler(oscMessage: OscMessage){<br>
handler.SetAllMessageHandler(AllMessageHandler);
var msgString = Osc.OscMessageToString(oscMessage);<br>
}
var msgAddress = oscMessage.Address;<br>
</source>
var msgValue = oscMessage.Values[0];</code> <br><br>
The AllMessageHandler() function is where the Osc happens. This function unpacks the Osc signals, so you can address them in other functions. In this function you can command, whenever A happens, you want FunctionB() to be executed. <br>
So you typed all that code and there are no errors but that stupid thing still won't do what it should - try Debug.Logs! Just add them everywhere! They can tell you what parts of your script are accessed after you press Play. <br><code>  
<source lang="javascript">
Debug.Log("Stakkars meg, som har skrevet 50 Debug.Logs");<br></code>
public function AllMessageHandler(oscMessage: OscMessage){
The lines will be written in the console section of Unity once they are accessed.<br>  
var msgString = Osc.OscMessageToString(oscMessage);
var msgAddress = oscMessage.Address;
var msgValue = oscMessage.Values[0];
</source>
So you typed all that code and there are no errors but that stupid thing still won't do what it should - try Debug.Logs! Just add them everywhere! They can tell you what parts of your script are accessed after you press Play. <br>
<source lang="javascript">
Debug.Log("Stakkars meg, som har skrevet 50 Debug.Logs");<br>
</source>
The lines will be written in the console section of Unity once they are accessed.<br><br> 
[[File:50Debug_Logs.png]]
[[File:50Debug_Logs.png]]