private void DrawCameraButton(MuMechModuleHullCamera camera, int line) { var saveRect = new Rect(LeftIndent, ContentTop + line * EntryHeight, ContentWidth, EntryHeight); if (GUI.Button(saveRect, GetCameraName(camera))) { OpenCameraInstance(camera); } }
public void OpenCameraInstance(MuMechModuleHullCamera camera) { if (GuiEnabled && _gameUiToggle) { if (!Core.TrackedCameras.ContainsKey(camera.GetInstanceID())) { var newCamera = new TrackingCamera(camera.GetInstanceID(), camera); StartCoroutine(newCamera.SendCameraImage()); Core.TrackedCameras.Add(camera.GetInstanceID(), newCamera); } } }
protected static void CycleCamera(int direction) { DebugOutput(String.Format("CycleMainCamera({0})", direction)); // Find the next camera to switch to, deactivate the current camera and activate the new one. MuMechModuleHullCamera newCam = sCurrentCamera; // Iterates the number of cameras and returns as soon as a camera is chosen. // Then if no camera is chosen, restore main camera as a last-ditch effort. for (int i = 0; i < sCameras.Count + 1; i += 1) { int nextCam = sCameras.IndexOf(newCam) + direction; if (nextCam >= sCameras.Count || nextCam < 0) { if (sAllowMainCamera && sCycleToMainCamera) { if (sCurrentCamera != null) { sCurrentCamera.camActive = false; sCurrentCamera = null; RestoreMainCamera(); } return; } nextCam = (direction > 0) ? 0 : sCameras.Count - 1; } newCam = sCameras[nextCam]; if (sCycleOnlyActiveVessel && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel != newCam.vessel) { continue; } if (newCam.camEnabled && newCam.part.State != PartStates.DEAD) { if (sCurrentCamera != null) { sCurrentCamera.camActive = false; } sCurrentCamera = newCam; sCurrentCamera.camActive = true; return; } } // Failed to find a camera including cycling back to the one we started from. Default to main as a last-ditch effort. if (sCurrentCamera != null) { sCurrentCamera.camActive = false; sCurrentCamera = null; RestoreMainCamera(); } }
protected static void RestoreMainCamera() { DebugOutput("RestoreMainCamera"); sCam.transform.parent = sOrigParent; sCam.transform.localPosition = sOrigPosition; sCam.transform.localRotation = sOrigRotation; Camera.main.nearClipPlane = sOrigClip; sCam.SetFoV(sOrigFov); if (FlightGlobals.ActiveVessel != null && HighLogic.LoadedScene == GameScenes.FLIGHT) { sCam.setTarget(FlightGlobals.ActiveVessel.transform); } sOrigParent = null; if (sCurrentCamera != null) { sCurrentCamera.camActive = false; } sCurrentCamera = null; }
public void toMainCamera() { if ((cam != null) && (cam.transform != null)) { cam.transform.parent = origParent; Camera.mainCamera.nearClipPlane = origClip; foreach (Camera c in cam.GetComponentsInChildren <Camera>()) { c.fov = origFoV; } cam.setTarget(FlightGlobals.ActiveVessel.transform); if (currentCamera != null) { currentCamera.camActive = false; } currentCamera = null; MapView.EnterMapView(); MapView.ExitMapView(); } }
public TrackingCamera(int id, MuMechModuleHullCamera hullcamera) { Id = id; _hullcamera = hullcamera; TargetCamRenderTexture = new RenderTexture(Settings.Width, Settings.Height, 24, RenderTextureFormat.ARGB32) { antiAliasing = 1 }; TargetCamRenderTexture.Create(); CalculateInitialSize(); _windowWidth = _adjCamImageWidthSize + 3 * ButtonHeight + 16 + 2 * Gap; _windowHeight = _adjCamImageHeightSize + 23; _windowRect = new Rect(Screen.width - _windowWidth, Screen.height - _windowHeight, _windowWidth, _windowHeight); SetCameras(); Enabled = true; }
public void ActivateCamera() { if (part.State == PartStates.DEAD) { return; } camActive = !camActive; if (!camActive && (cam != null)) { toMainCamera(); } else { if ((currentCamera != null) && (currentCamera != this)) { currentCamera.camActive = false; } currentCamera = this; } }
public void CleanUp() { if (camActive) { toMainCamera(); } if (currentCamera == this) { currentCamera = null; } if (currentHandler == this) { currentHandler = null; } if (cameras.Contains(this)) { cameras.Remove(this); } }
protected void Activate() { DebugOutput("Activate"); if (part.State == PartStates.DEAD) { return; } if (camActive) { if (sAllowMainCamera) { RestoreMainCamera(); } else { CycleCamera(1); } return; } sCurrentCamera = this; camActive = true; }
public void CleanUp() { DebugOutput("Cleanup"); if (sCurrentHandler == this) { sCurrentHandler = null; } if (sCurrentCamera == this) { // On destruction, revert to main camera so we're not left hanging. LeaveCamera(); } if (sCameras.Contains(this)) { sCameras.Remove(this); DebugOutput(String.Format("Removed, now {0}", sCameras.Count)); // This happens when we're saving and reloading. if (sCameras.Count < 1 && sOrigParent != null) { sCurrentCamera = null; RestoreMainCamera(); } } }
public void Update() { // In the VAB if (vessel == null) { return; } if (sCurrentHandler == null) { sCurrentHandler = this; } if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Flight) { return; } if (sActionFlags.deactivateCamera || CAMERA_RESET.GetKeyDown() || GameSettings.CAMERA_NEXT.GetKeyDown()) { LeaveCamera(); sActionFlags.deactivateCamera = false; } if (sActionFlags.nextCamera || (sCurrentHandler == this && CAMERA_NEXT.GetKeyDown())) { CycleCamera(1); sActionFlags.nextCamera = false; } if (sActionFlags.prevCamera || (sCurrentHandler == this && CAMERA_PREV.GetKeyDown())) { CycleCamera(-1); sActionFlags.prevCamera = false; } /* if ((sCurrentCamera == this) && adjustMode) { if (Input.GetKeyUp(KeyCode.Keypad8)) { cameraPosition += cameraUp * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad2)) { cameraPosition -= cameraUp * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad6)) { cameraPosition += cameraForward * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad4)) { cameraPosition -= cameraForward * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad7)) { cameraClip += 0.05f; } if (Input.GetKeyUp(KeyCode.Keypad1)) { cameraClip -= 0.05f; } if (Input.GetKeyUp(KeyCode.Keypad9)) { cameraFoV += 5; } if (Input.GetKeyUp(KeyCode.Keypad3)) { cameraFoV -= 5; } if (Input.GetKeyUp(KeyCode.KeypadMinus)) { print("Position: " + cameraPosition + " - Clip = " + cameraClip + " - FoV = " + cameraFoV); } } */ }
public void Update() { if (vessel == null) { return; } Events["ActivateCamera"].guiName = camActive ? "Deactivate Camera" : "Activate Camera"; Events["EnableCamera"].guiName = camEnabled ? "Disable Camera" : "Enable Camera"; if (currentHandler == null) { currentHandler = this; } if (currentHandler == this) { cameras.RemoveAll(item => item == null); if (Input.GetKeyUp(cameraKeyNext)) { if (currentCamera != null) { int curCam = cameras.IndexOf(currentCamera); if (curCam + 1 >= cameras.Count) { toMainCamera(); } else { cameras[curCam + 1].ActivateCamera(); } } else { cameras.First().ActivateCamera(); } } if (Input.GetKeyUp(cameraKeyPrev)) { if (currentCamera != null) { int curCam = cameras.IndexOf(currentCamera); if (curCam < 1) { toMainCamera(); } else { cameras[curCam - 1].ActivateCamera(); } } else { cameras.Last().ActivateCamera(); } } } if ((currentCamera == this) && adjustMode) { if (Input.GetKeyUp(KeyCode.Keypad8)) { cameraPosition += cameraUp * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad2)) { cameraPosition -= cameraUp * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad6)) { cameraPosition += cameraForward * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad4)) { cameraPosition -= cameraForward * 0.1f; } if (Input.GetKeyUp(KeyCode.Keypad7)) { cameraClip += 0.05f; } if (Input.GetKeyUp(KeyCode.Keypad1)) { cameraClip -= 0.05f; } if (Input.GetKeyUp(KeyCode.Keypad9)) { cameraFoV += 5; } if (Input.GetKeyUp(KeyCode.Keypad3)) { cameraFoV -= 5; } if (Input.GetKeyUp(KeyCode.KeypadMinus)) { print("Position: " + cameraPosition + " - Clip = " + cameraClip + " - FoV = " + cameraFoV); } } }
public void FixedUpdate() { // In the VAB if (vessel == null) { return; } if (part.State == PartStates.DEAD) { if (camActive) { LeaveCamera(); } Events["ActivateCamera"].guiActive = false; Events["EnableCamera"].guiActive = false; camEnabled = false; camActive = false; DirtyWindow(); CleanUp(); return; } if (!sAllowMainCamera && sCurrentCamera == null && !vessel.isEVA) { camActive = true; sCurrentCamera = this; } if (!camActive) { return; } if (!camEnabled) { CycleCamera(1); return; } if (sCam == null) { sCam = FlightCamera.fetch; // No idea if fetch returns null in normal operation (i.e. when there isn't a game breaking bug going on already) // but the original code had similar logic. if (sCam == null) { return; } } // Either we haven't set sOriginParent, or we've nulled it when restoring the main camera, so we save it again here. if (sOrigParent == null) { SaveMainCamera(); } sCam.setTarget(null); sCam.transform.parent = (cameraTransformName.Length > 0) ? part.FindModelTransform(cameraTransformName) : part.transform; sCam.transform.localPosition = cameraPosition; sCam.transform.localRotation = Quaternion.LookRotation(cameraForward, cameraUp); sCam.SetFoV(cameraFoV); Camera.main.nearClipPlane = cameraClip; // If we're only allowed to cycle the active vessel and viewing through a camera that's not the active vessel any more, then cycle to one that is. if (sCycleOnlyActiveVessel && FlightGlobals.ActiveVessel != null && FlightGlobals.ActiveVessel != vessel) { CycleCamera(1); } base.OnFixedUpdate(); }
public void toMainCamera() { if ((cam != null) && (cam.transform != null)) { cam.transform.parent = origParent; Camera.mainCamera.nearClipPlane = origClip; foreach (Camera c in cam.GetComponentsInChildren<Camera>()) { c.fov = origFoV; } cam.setTarget(FlightGlobals.ActiveVessel.transform); if (currentCamera != null) { currentCamera.camActive = false; } currentCamera = null; MapView.EnterMapView(); MapView.ExitMapView(); } }
public void Update() { // In the VAB if (vessel == null) { return; } if (sCurrentHandler == null) { sCurrentHandler = this; } if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Flight) { return; } if (sActionFlags.deactivateCamera || CAMERA_RESET.GetKeyDown() || GameSettings.CAMERA_NEXT.GetKeyDown()) { LeaveCamera(); sActionFlags.deactivateCamera = false; } if (sActionFlags.nextCamera || (sCurrentHandler == this && CAMERA_NEXT.GetKeyDown())) { CycleCamera(1); sActionFlags.nextCamera = false; } if (sActionFlags.prevCamera || (sCurrentHandler == this && CAMERA_PREV.GetKeyDown())) { CycleCamera(-1); sActionFlags.prevCamera = false; } /* * if ((sCurrentCamera == this) && adjustMode) * { * if (Input.GetKeyUp(KeyCode.Keypad8)) * { * cameraPosition += cameraUp * 0.1f; * } * if (Input.GetKeyUp(KeyCode.Keypad2)) * { * cameraPosition -= cameraUp * 0.1f; * } * if (Input.GetKeyUp(KeyCode.Keypad6)) * { * cameraPosition += cameraForward * 0.1f; * } * if (Input.GetKeyUp(KeyCode.Keypad4)) * { * cameraPosition -= cameraForward * 0.1f; * } * if (Input.GetKeyUp(KeyCode.Keypad7)) * { * cameraClip += 0.05f; * } * if (Input.GetKeyUp(KeyCode.Keypad1)) * { * cameraClip -= 0.05f; * } * if (Input.GetKeyUp(KeyCode.Keypad9)) * { * cameraFoV += 5; * } * if (Input.GetKeyUp(KeyCode.Keypad3)) * { * cameraFoV -= 5; * } * if (Input.GetKeyUp(KeyCode.KeypadMinus)) * { * print("Position: " + cameraPosition + " - Clip = " + cameraClip + " - FoV = " + cameraFoV); * } * } */ }
private string GetCameraName(MuMechModuleHullCamera muMechModuleHullCamera) { return(muMechModuleHullCamera.vessel.GetDisplayName() + "." + muMechModuleHullCamera.cameraName); }