void Start() { Debug.Log("EventManager started"); if (Instance == null) { Instance = this; } else { Debug.LogWarning("BeKerbal: There is more than one EventManager in the current scene. Destroying the excess."); Destroy(this); } _IVAControl = new IVAControl(); _EVAControl = new EVAControl(); InputLockManager.SetControlLock(ControlTypes.MAP, BeKerbal.Settings.MapControl_LockID); _CurrentKerbal = new KerbalInfo(FlightGlobals.ActiveVessel); if (_CurrentKerbal.IsEVA) { OnStartEVA(_CurrentKerbal); } else { OnStartIVA(_CurrentKerbal); } }
public void Start(KerbalInfo kerbalInfo) { Kerbal kerbal = kerbalInfo.Kerbal; CameraManager cameraManager = CameraManager.Instance; cameraManager.SetCameraIVA(kerbal, true); }
public void Stop(KerbalInfo kerbalInfo) { FlightCamera flightCam = FlightCamera.fetch; Vessel vessel = kerbalInfo.Vessel; KerbalEVA evaInst = kerbalInfo.EVA; foreach (Component component in vessel.transform.GetComponentsInChildren(typeof(Transform), true)) { /*if (component.name.Contains(BeKerbal.Settings.EVA_HelmetColliderComponentName) && _OriginHelmetColliderRadius == -1.0f) * { * component.GetComponent<SphereCollider>().radius = _OriginHelmetColliderRadius; * _OriginHelmetColliderRadius = -1.0f; * }*/ foreach (string name in BeKerbal.Settings.EVA_HiddenComponentsName) { if (component.name.Contains(name) && component.renderer != null) { component.renderer.enabled = true; break; } } } flightCam.ActivateUpdate(); Screen.lockCursor = false; }
private void OnSwitchKerbal(KerbalInfo previous, KerbalInfo next) { if (next.EVA != null) { string pName = "NULL"; if (previous.Kerbal != null) { pName = previous.Kerbal.crewMemberName; } string nName = "NULL"; if (next.Kerbal != null) { nName = next.Kerbal.crewMemberName; } if (previous.IsEVA) { // We switch kerbals from EVA to EVA Debug.Log("Switched from Kerbal EVA " + pName + " to EVA " + nName); } else { // We switch kerbals from IVA to EVA Debug.Log("Switched from Kerbal IVA " + pName + " to EVA " + nName); } } }
public KerbalInfo(KerbalInfo other) { EVA = other.EVA; IsEVA = other.IsEVA; Kerbal = other.Kerbal; Vessel = other.Vessel; }
void Update() { if (FlightDriver.Pause) { if (_CurrentKerbal.IsEVA) { OnPausedUpdateEVA(_CurrentKerbal); } else if (!_CurrentKerbal.IsEVA) { OnPausedUpdateIVA(_CurrentKerbal); } return; } KerbalInfo lastKerbal = _CurrentKerbal; KerbalInfo currentKerbal = new KerbalInfo(FlightGlobals.ActiveVessel); if (!_KerbalEquals(lastKerbal, currentKerbal)) { Debug.Log("Switch pEVA=" + lastKerbal.IsEVA + " nEVA=" + currentKerbal.IsEVA); OnSwitchKerbal(lastKerbal, currentKerbal); if (lastKerbal.IsEVA && currentKerbal.IsEVA) { OnStopEVA(lastKerbal); OnStartEVA(currentKerbal); } else if (!lastKerbal.IsEVA && !currentKerbal.IsEVA) { OnStopIVA(lastKerbal); OnStartIVA(currentKerbal); } } if (!lastKerbal.IsEVA && currentKerbal.IsEVA) { OnStopIVA(currentKerbal); OnStartEVA(currentKerbal); } else if (lastKerbal.IsEVA && !currentKerbal.IsEVA) { OnStopEVA(currentKerbal); OnStartIVA(currentKerbal); } if (lastKerbal.IsEVA && currentKerbal.IsEVA) { OnUpdateEVA(currentKerbal); } else if (!lastKerbal.IsEVA && !currentKerbal.IsEVA) { OnUpdateIVA(currentKerbal); } _CurrentKerbal = new KerbalInfo(currentKerbal); }
private void OnUpdateIVA(KerbalInfo kerbal) { _Camera.Update(kerbal); Debug.Log("G"); if (Input.GetKeyDown(BeKerbal.Settings.IVA_GoToEVAKeyCode)) { CameraManager.Instance.SetCameraFlight(); FlightEVA.SpawnEVA(kerbal.Kerbal); } Debug.Log("H"); }
protected virtual void OnPausedUpdateEVA(KerbalInfo kerbal) { if (PausedUpdateEVA != null) { try { PausedUpdateEVA(kerbal); } catch (Exception e) { Debug.LogError("Exception in PausedUpdateEVA: " + e.Message); } } }
protected virtual void OnSwitchKerbal(KerbalInfo previous, KerbalInfo next) { if (SwitchKerbal != null) { try { SwitchKerbal(previous, next); } catch (Exception e) { Debug.LogError("Exception in SwitchKerbal: " + e.Message); } } }
protected virtual void OnStartEVA(KerbalInfo kerbal) { if (StartEVA != null) { try { StartEVA(kerbal); } catch (Exception e) { Debug.LogError("Exception in StartEVA: " + e.Message); } } }
private void OnUpdateEVA(KerbalInfo kerbal) { bool pressedMove = GameSettings.EVA_forward.GetKey() || GameSettings.EVA_back.GetKey() || GameSettings.EVA_left.GetKey() || GameSettings.EVA_right.GetKey() || GameSettings.EVA_Jump.GetKey(); bool pressedJetpackMove = false; if (kerbal.EVA.JetpackDeployed && !kerbal.Vessel.LandedOrSplashed) { pressedJetpackMove |= GameSettings.EVA_Pack_back.GetKey() || GameSettings.EVA_Pack_forward.GetKey() || GameSettings.EVA_Pack_left.GetKey() || GameSettings.EVA_Pack_right.GetKey() || GameSettings.EVA_Pack_down.GetKey() || GameSettings.EVA_Pack_up.GetKey() || GameSettings.EVA_yaw_left.GetKey() || GameSettings.EVA_yaw_right.GetKey(); } pressedMove |= pressedJetpackMove; _Camera.PressedMove = pressedMove; _Camera.Update(kerbal); }
//private float _OriginHelmetColliderRadius = -1.0f; // Not used anymore but might be used again later public void Start(KerbalInfo kerbalInfo) { PressedMove = false; FlightCamera flightCam = FlightCamera.fetch; Vessel vessel = kerbalInfo.Vessel; KerbalEVA evaInst = kerbalInfo.EVA; foreach (Component component in vessel.transform.GetComponentsInChildren(typeof(Transform), true)) { /*if (component.name.Contains(BeKerbal.Settings.EVA_HelmetColliderComponentName) && _OriginHelmetColliderRadius == -1.0f) * { * _OriginHelmetColliderRadius = component.GetComponent<SphereCollider>().radius; * component.GetComponent<SphereCollider>().radius *= BeKerbal.Settings.EVA_HelmetColliderRadiusFactor; * }*/ if (component.name.Contains(BeKerbal.Settings.EVA_RagdollComponentReferenceName)) { _HeadTransform = component.transform; } foreach (string name in BeKerbal.Settings.EVA_HiddenComponentsName) { if (component.name.Contains(name) && component.renderer != null) { component.renderer.enabled = false; break; } } } flightCam.DeactivateUpdate(); _Pitch = 0.0f; _Yaw = 0.0f; _Forward = evaInst.transform.forward; _Up = evaInst.transform.up; _CursorLocked = true; flightCam.transform.position = Vector3.zero; }
public void Update(KerbalInfo kerbalInfo) { Kerbal kerbal = kerbalInfo.Kerbal; CameraManager cameraManager = CameraManager.Instance; if (cameraManager.currentCameraMode == CameraManager.CameraMode.Flight) { if (kerbal != null) { try { cameraManager.SetCameraIVA(kerbal, true); } catch { cameraManager.SetCameraIVA(); } } else { cameraManager.SetCameraIVA(); } } }
public void Stop(KerbalInfo kerbalInfo) { Kerbal kerbal = kerbalInfo.Kerbal; }
private void OnPausedUpdateEVA(KerbalInfo kerbal) { _Camera.PausedUpdate(kerbal); }
private void OnStopEVA(KerbalInfo kerbal) { _Camera.Stop(kerbal); }
private void OnStartEVA(KerbalInfo kerbal) { _Camera.Start(kerbal); }
public void PausedUpdate(KerbalInfo kerbalInfo) { }
private bool _KerbalEquals(KerbalInfo a, KerbalInfo b) { return(_KerbalEquals(a.Kerbal, b.Kerbal)); }
public void Update(KerbalInfo kerbalInfo) { FlightCamera flightCam = FlightCamera.fetch; Vessel vessel = kerbalInfo.Vessel; KerbalEVA evaInst = kerbalInfo.EVA; if (flightCam.updateActive) { flightCam.DeactivateUpdate(); } float yaw = 0.0f; float pitch = 0.0f; if (Input.GetKeyDown(KeyCode.LeftAlt)) { _CursorLocked = !_CursorLocked; } Screen.lockCursor = _CursorLocked; if (_CursorLocked && !evaInst.isRagdoll) { yaw = Input.GetAxis("Mouse X") * BeKerbal.Settings.EVA_LookSentivity; pitch = Input.GetAxis("Mouse Y") * BeKerbal.Settings.EVA_LookSentivity; } if (!evaInst.isRagdoll) { evaInst.fFwd = _Forward; evaInst.fUp = _Up; } flightCam.mainCamera.nearClipPlane = BeKerbal.Settings.EVA_NearClip; flightCam.transform.position = vessel.ReferenceTransform.position; flightCam.transform.rotation = Quaternion.identity; if (!evaInst.isRagdoll) { if (vessel.LandedOrSplashed || evaInst.OnALadder) // Is walking on a surface or climbing a ladder { evaInst.CharacterFrameMode = false; evaInst.CharacterFrameModeToggle = true; _Yaw += yaw; float absYaw = Mathf.Abs(_Yaw); float yawExceed = Mathf.Max(0.0f, Mathf.Abs(_Yaw) - BeKerbal.Settings.EVA_MaxYaw) * Mathf.Sign(_Yaw); _Yaw = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw); _Pitch -= pitch; _Pitch = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch); if (evaInst.OnALadder) { flightCam.transform.rotation = Quaternion.LookRotation(evaInst.transform.forward, evaInst.transform.up) * SpaceNavigator.Rotation; } else { flightCam.transform.rotation = Quaternion.LookRotation(evaInst.fFwd, evaInst.transform.up) * SpaceNavigator.Rotation; if (PressedMove) { float partYaw = _Yaw * BeKerbal.Settings.EVA_ViewTurnPercent; _Yaw -= partYaw; flightCam.transform.Rotate(Vector3.up * (yawExceed + partYaw), Space.Self); } } _Forward = flightCam.transform.forward; _Up = flightCam.transform.up; } else if (evaInst.JetpackDeployed) // Is using jetpack in the air { evaInst.CharacterFrameMode = false; evaInst.CharacterFrameModeToggle = true; //flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation; flightCam.transform.rotation = Quaternion.LookRotation(evaInst.fFwd, evaInst.fUp) * SpaceNavigator.Rotation; if (_CursorLocked) { _Yaw += yaw; _Yaw = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw); _Pitch -= pitch; _Pitch = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch); if (PressedMove) { float partYaw = _Yaw * BeKerbal.Settings.EVA_ViewTurnPercent; float partPitch = _Pitch * BeKerbal.Settings.EVA_ViewTurnPercent; _Yaw -= partYaw; _Pitch -= partPitch; flightCam.transform.rotation *= Quaternion.Euler(-(pitch - partPitch), yaw + partYaw, 0.0f); } } _Forward = flightCam.transform.forward; _Up = flightCam.transform.up; } else // Is falling without jetpack and not in ragdoll yet (probably jumping or drifting in the void) { evaInst.CharacterFrameMode = true; evaInst.CharacterFrameModeToggle = false; _Yaw += yaw; _Yaw = Mathf.Clamp(_Yaw, BeKerbal.Settings.EVA_MinYaw, BeKerbal.Settings.EVA_MaxYaw); _Pitch -= pitch; _Pitch = Mathf.Clamp(_Pitch, BeKerbal.Settings.EVA_MinPitch, BeKerbal.Settings.EVA_MaxPitch); flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation; _Forward = evaInst.transform.forward; } } else // Is in ragdoll or TODO(is recovering from ragdoll) { evaInst.CharacterFrameMode = true; evaInst.CharacterFrameModeToggle = false; _Yaw = Mathf.Lerp(_Yaw, 0.0f, 2.0f * Time.deltaTime); _Pitch = Mathf.Lerp(_Pitch, 0.0f, 2.0f * Time.deltaTime); if (!evaInst.animation.enabled) // true ragdoll { flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation; } else // recovering { flightCam.transform.rotation = Quaternion.LookRotation(-_HeadTransform.up, -_HeadTransform.right) * SpaceNavigator.Rotation; _Forward = evaInst.transform.forward; _Up = evaInst.transform.up; } } flightCam.transform.Translate(BeKerbal.Settings.EVA_HeadLocation + BeKerbal.Settings.EVA_EyeOffset, Space.Self); flightCam.transform.Rotate(Vector3.up * _Yaw, Space.Self); flightCam.transform.Rotate(Vector3.right * _Pitch, Space.Self); }
public void PausedUpdate(KerbalInfo kerbalInfo) { Screen.lockCursor = false; }