/* ===================== * 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(); } } }
/* ===================== * UNITY PLAYER EVENT HOOKS * ===================== */ // Function called when Unity Player is loaded. public IEnumerator Start() { // Make sure that this gameobject survives across scene reloads DontDestroyOnLoad(this.gameObject); // Get application version flight_goggles_version = Application.version; Debug.Log("FlightGoggles version: " + flight_goggles_version); // Fixes for Unity/NetMQ conflict stupidity. AsyncIO.ForceDotNet.Force(); socket_lock = new object(); // Instantiate sockets InstantiateSockets(); // Check if previously saved ip exists client_ip = PlayerPrefs.GetString(client_ip_pref_key, client_ip_default); if (!Application.isEditor) { // Check if FlightGoggles should change its connection ports (for parallel operation) // Check if the program should use CLI arguments for IP. pose_client_port = Int32.Parse(GetArg("-input-port", "10253")); video_client_port = Int32.Parse(GetArg("-output-port", "10254")); // Check if the program should use CLI arguments for IP. string client_ip_from_cli = GetArg("-client-ip", ""); if (client_ip_from_cli.Length > 0) { ConnectToClient(client_ip_from_cli); } else { ConnectToClient(client_ip); } // Check if the program should use CLI arguments for IP. obstacle_perturbation_file = GetArg("-obstacle-perturbation-file", ""); // Disable fullscreen. Screen.fullScreen = false; Screen.SetResolution(1024, 768, false); } else { // Try to connect to the default ip ConnectToClient(client_ip); } // Init simple splash screen Text text_obj = splashScreen.GetComponentInChildren <Text>(true); InputField textbox_obj = splashScreen.GetComponentInChildren <InputField>(true); text_obj.text = "FlightGoggles Simulation Environment" + Environment.NewLine + flight_goggles_version + Environment.NewLine + Environment.NewLine + "Waiting for connection from client..."; textbox_obj.text = client_ip; splashScreen.SetActive(true); // 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(); } } }