protected void Activate() { DebugOutput("Activate"); if (part.State == PartStates.DEAD) { return; } if (camActive) { if (sAllowMainCamera) { RestoreMainCamera(); } else { DebugOutput(" 6"); CycleCamera(1); } return; } sCurrentCamera = this; camActive = true; changeCameraMode(); }
public void CleanUp() { DebugOutput("Cleanup"); if (sCurrentHandler == this) { DebugOutput("sCurrentHandler is this"); sCurrentHandler = null; } if (sCurrentCamera == this) { DebugOutput("If it's the current camera"); // 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 && !this.camActive) { DebugOutput("Set sCurrentCamera to null"); sCurrentCamera = null; DebugOutput("RestoreMainCamera"); RestoreMainCamera(); DebugOutput("RestoringMainCamera"); } } }
protected static void RestoreMainCamera() { DebugOutput("RestoreMainCamera"); sCam.transform.parent = sOrigParent; sCam.transform.localPosition = sOrigPosition; sCam.transform.localRotation = sOrigRotation; Camera.main.nearClipPlane = sOrigClip; sCurrentCamera.mt.SetCameraMode(CameraFilter.eCameraMode.Normal); sCam.SetFoV(sOrigFov); sCam.ActivateUpdate(); if (FlightGlobals.ActiveVessel != null && HighLogic.LoadedScene == GameScenes.FLIGHT) { //sCam.SetTarget(FlightGlobals.ActiveVessel.transform, FlightCamera.TargetMode.Transform); sCam.SetTarget(FlightGlobals.ActiveVessel.transform, FlightCamera.TargetMode.Vessel); } sOrigParent = null; if (sCurrentCamera != null) { sCurrentCamera.camActive = false; } sCurrentCamera = null; }
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) { // Check if cycle direction is referse and if the current cam is the first hullcam if (direction == -1 && sCameras.IndexOf(sCurrentCamera) == 0) { sCurrentCamera.camActive = false; RestoreMainCamera(); return; } int nextCam = sCameras.IndexOf(newCam) + direction; if (nextCam >= sCameras.Count) { if (sAllowMainCamera && sCycleToMainCamera) { if (sCurrentCamera != null) { sCurrentCamera.camActive = false; 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; changeCameraMode(); sCurrentCamera.camActive = true; IdentifyCamera(); 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(); } }
private void onGameSceneLoadRequested(GameScenes gameScene) { if (sCurrentCamera != null) { print("Clearing camera list"); sCameras.Clear(); sCurrentCamera.mt.SetCameraMode(CameraFilter.eCameraMode.Normal); sCurrentCamera = null; } }
protected static void RestoreMainCamera() { DebugOutput("RestoreMainCamera"); if (sCam != null) { sCam.transform.parent = sOrigParent; sCam.transform.localPosition = sOrigPosition; sCam.transform.localRotation = sOrigRotation; sCam.SetFoV(sOrigFov); sCam.ActivateUpdate(); if (FlightGlobals.ActiveVessel != null && HighLogic.LoadedScene == GameScenes.FLIGHT) { //sCam.SetTarget(FlightGlobals.ActiveVessel.transform, FlightCamera.TargetMode.Transform); sCam.SetTarget(FlightGlobals.ActiveVessel.transform, FlightCamera.TargetMode.Vessel); } sOrigParent = null; } if (sCurrentCamera != null) { sCurrentCamera.mt.SetCameraMode(CameraFilter.eCameraMode.Normal); sCurrentCamera.camActive = false; } sCurrentCamera = null; Camera.main.nearClipPlane = sOrigClip; ///////////////////////////////////// if (sOrigVesselTransformPart != null) { if (GameSettings.MODIFIER_KEY.GetKey(false)) { #if false ModuleDockingNode mdn = sOrigVesselTransformPart.FindModuleImplementing <ModuleDockingNode>(); if (mdn != null) { sOrigVesselTransformPart.SetReferenceTransform(mdn.controlTransform); } else #endif { // sOrigVesselTransformPart.SetReferenceTransform(sOrigVesselTransformPart.GetReferenceTransform()); } FlightGlobals.ActiveVessel.SetReferenceTransform(sOrigVesselTransformPart, true); ScreenMessages.PostScreenMessage(locControlPointRestored + " " + sOrigVesselTransformPart.partInfo.title); sOrigVesselTransformPart = null; } } ///////////////////////////////////// }
public void FixedUpdate() { // In the VAB if (vessel == null) { return; } // following "if" added by jbb if (MapView.MapIsEnabled) { 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) { DebugOutput(" 3"); 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.SetTargetNone(); sCam.transform.parent = (cameraTransformName.Length > 0) ? part.FindModelTransform(cameraTransformName) : part.transform; sCam.DeactivateUpdate(); 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) { DebugOutput(" 4"); CycleCamera(1); } base.OnFixedUpdate(); }
public void LateUpdate() { // In the VAB if (vessel == null) { return; } if (sCurrentHandler == null) { sCurrentHandler = this; } if (sCurrentCamera != null) { if (sCurrentCamera.vessel != FlightGlobals.ActiveVessel) { Vector3d activeVesselPos = FlightGlobals.ActiveVessel.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime()) + FlightGlobals.ActiveVessel.orbit.referenceBody.position; Vector3d targetVesselPos = sCurrentCamera.vessel.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime()) + sCurrentCamera.vessel.orbit.referenceBody.position; sCameraDistance = (activeVesselPos - targetVesselPos).magnitude; if (sCameraDistance >= 2480) { LeaveCamera(); } } } if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.Flight) { return; } #if true if (sActionFlags.deactivateCamera || CAMERA_RESET.GetKeyDown() || GameSettings.CAMERA_NEXT.GetKeyDown()) { LeaveCamera(); sActionFlags.deactivateCamera = false; } #endif if (sActionFlags.nextCamera || (sCurrentHandler == this && CAMERA_NEXT.GetKeyDown())) { CycleCamera(1); sActionFlags.nextCamera = false; } #if true if (sActionFlags.prevCamera || (sCurrentHandler == this && CAMERA_PREV.GetKeyDown())) { if (sCameras.IndexOf(sCurrentCamera) != -1) { CycleCamera(-1); sActionFlags.prevCamera = false; } else { DebugOutput(" 2"); CycleCamera(sCameras.Count); } } #endif /* * if (sCurrentCamera == this) * { * 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); * } * } */ doOnUpdate(); }
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++) { // Check if cycle direction is referse and if the current cam is the first hullZcam if (direction == -1 && sCameras.IndexOf(sCurrentCamera) == 0) { sCurrentCamera.camActive = false; RestoreMainCamera(); return; } int nextCam = sCameras.IndexOf(newCam) + direction; if (nextCam >= sCameras.Count) { if (sAllowMainCamera && sCycleToMainCamera) { if (sCurrentCamera != null) { sCurrentCamera.camActive = false; RestoreMainCamera(); } return; } nextCam = (direction > 0) ? 0 : sCameras.Count - 1; } newCam = sCameras[nextCam]; #if true if (newCam.vessel == FlightGlobals.ActiveVessel) { if (GameSettings.MODIFIER_KEY.GetKey(false)) { ModuleDockingNode mdn = newCam.part.FindModuleImplementing <ModuleDockingNode>(); if (mdn != null) { if (sOrigVesselTransformPart == null) { sOrigVesselTransformPart = FlightGlobals.ActiveVessel.GetReferenceTransformPart(); ScreenMessages.PostScreenMessage(locOriginalControlPoint + ": " + sOrigVesselTransformPart.partInfo.title); } newCam.part.SetReferenceTransform(mdn.controlTransform); FlightGlobals.ActiveVessel.SetReferenceTransform(newCam.part, true); ScreenMessages.PostScreenMessage(locControlPointChanged + " " + newCam.part.partInfo.title); } } } #endif 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; changeCameraMode(); sCurrentCamera.camActive = true; IdentifyCamera(); 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(); } }