/// <summary> /// Called by Unity each frame /// </summary> public void Update() { if (_pollingEnabled) { if (!VrControlsAvailable() || !InCockpit()) { _pollingEnabled = false; _waitingForVrJoystick = false; _vrJoystick = null; _vrThrottle = null; Log("Left cockpit"); } } else { if (!VrControlsAvailable() && InCockpit() && !_waitingForVrJoystick) { // Entered cockpit Log("Entered cockpit"); _waitingForVrJoystick = true; StartCoroutine(FindScripts()); return; } } // Take state from physical stick and apply to VRJoystick PollSticks(); if (!VrControlsAvailable()) { return; } SendUpdates(); }
private IEnumerator FindScripts() { while (_vrJoystick == null) { //Searches the whole game scene for the script, there should only be one so its fine _vrJoystick = FindObjectOfType <VRJoystick>(); _vrThrottle = FindObjectOfType <VRThrottle>(); if (VrControlsAvailable()) { continue; } Log("Waiting for VRJoystick..."); yield return(new WaitForSeconds(1)); } _waitingForVrJoystick = false; _pollingEnabled = true; Log("Got VRJoystick"); }
void RepairAircraft() { FlightAssist flightAssist = GetComponentInChildren <FlightAssist>(); if (flightAssist != null) { flightAssist.assistEnabled = true; } else { Debug.Log("Could not fix flight assists"); } RCSController rcsController = GetComponentInChildren <RCSController>(); if (rcsController != null) { Traverse.Create(rcsController).Field("alive").SetValue(true); } else { Debug.Log("Could not fix rcs controller"); } Battery battery = GetComponentInChildren <Battery>(); if (battery != null) { Traverse.Create(battery).Field("isAlive").SetValue(true); battery.Connect(); } else { Debug.Log("Could not fix battery"); } GameObject hud = GameObject.Find("CollimatedHud"); if (hud != null) { hud.SetActive(true); } else { Debug.Log("Could not fix hud"); } GameObject hudWaypoint = GameObject.Find("WaypointLead"); if (hudWaypoint != null) { hudWaypoint.SetActive(true); } else { Debug.Log("Could not fix hudWaypoint"); } VRJoystick joystick = GetComponentInChildren <VRJoystick>(); if (joystick != null) { joystick.sendEvents = true; } else { Debug.Log("Could not fix joystick"); } VRInteractable[] levers = GetComponentsInChildren <VRInteractable>(); foreach (VRInteractable lever in levers) { lever.enabled = true; } Debug.Log("Fixed " + levers.Length + " levers"); }