/* =====================
* UNITY PLAYER EVENT HOOKS
* =====================
*/
// Function called when Unity Player is loaded.
public IEnumerator Start()
{
// Check if the program should use CLI arguments (with defaults)
if (!Application.isEditor)
{
pose_host = GetArg("-pose-host", pose_host_default);
video_host = GetArg("-video-host", video_host_default);
}
// Init simple splash screen
Text text_obj = splashScreen.GetComponentInChildren <Text>(true);
text_obj.text = "FlightGoggles Simulation Environment" + Environment.NewLine +
flight_goggles_version + Environment.NewLine + Environment.NewLine +
"Waiting for client connection..." + Environment.NewLine + Environment.NewLine +
"Pose input socket:" + Environment.NewLine + pose_host + Environment.NewLine + Environment.NewLine +
"Video output socket:" + Environment.NewLine + video_host;
splashScreen.SetActive(true);
// Fixes for Unity/NetMQ conflict stupidity.
AsyncIO.ForceDotNet.Force();
socket_lock = new object();
// Connect sockets
Debug.Log("Creating sockets.");
pull_socket = new NetMQ.Sockets.SubscriberSocket();
pull_socket.Options.ReceiveHighWatermark = 90;
pull_socket.Connect(pose_host);
// Setup subscriptions.
pull_socket.Subscribe("Pose");
push_socket = new NetMQ.Sockets.PublisherSocket();
push_socket.Connect(video_host);
Debug.Log("Sockets bound.");
// Initialize Internal State
internal_state = new UnityState_t();
// Do not try to do any processing this frame so that we can render our splash screen.
internal_state.screenSkipFrames = 1;
// Wait until end of frame to transmit images
while (true)
{
// Wait until all rendering + UI is done.
// Blocks until the frame is rendered.
yield return(new WaitForEndOfFrame());
// Check if this frame should be rendered.
if (internal_state.readyToRender)
{
// Read the frame from the GPU backbuffer and send it via ZMQ.
sendFrameOnWire();
}
}
}