Пример #1
0
        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);
            }
        }
Пример #2
0
        public void Start(KerbalInfo kerbalInfo)
        {
            Kerbal        kerbal        = kerbalInfo.Kerbal;
            CameraManager cameraManager = CameraManager.Instance;

            cameraManager.SetCameraIVA(kerbal, true);
        }
Пример #3
0
        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;
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
 public KerbalInfo(KerbalInfo other)
 {
     EVA    = other.EVA;
     IsEVA  = other.IsEVA;
     Kerbal = other.Kerbal;
     Vessel = other.Vessel;
 }
Пример #6
0
        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);
        }
Пример #7
0
        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");
        }
Пример #8
0
 protected virtual void OnPausedUpdateEVA(KerbalInfo kerbal)
 {
     if (PausedUpdateEVA != null)
     {
         try
         {
             PausedUpdateEVA(kerbal);
         }
         catch (Exception e)
         {
             Debug.LogError("Exception in PausedUpdateEVA: " + e.Message);
         }
     }
 }
Пример #9
0
 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);
         }
     }
 }
Пример #10
0
 protected virtual void OnStartEVA(KerbalInfo kerbal)
 {
     if (StartEVA != null)
     {
         try
         {
             StartEVA(kerbal);
         }
         catch (Exception e)
         {
             Debug.LogError("Exception in StartEVA: " + e.Message);
         }
     }
 }
Пример #11
0
        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);
        }
Пример #12
0
        //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;
        }
Пример #13
0
        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();
                }
            }
        }
Пример #14
0
 public void Stop(KerbalInfo kerbalInfo)
 {
     Kerbal kerbal = kerbalInfo.Kerbal;
 }
Пример #15
0
 private void OnPausedUpdateEVA(KerbalInfo kerbal)
 {
     _Camera.PausedUpdate(kerbal);
 }
Пример #16
0
 private void OnStopEVA(KerbalInfo kerbal)
 {
     _Camera.Stop(kerbal);
 }
Пример #17
0
 private void OnStartEVA(KerbalInfo kerbal)
 {
     _Camera.Start(kerbal);
 }
Пример #18
0
 public void PausedUpdate(KerbalInfo kerbalInfo)
 {
 }
Пример #19
0
 private bool _KerbalEquals(KerbalInfo a, KerbalInfo b)
 {
     return(_KerbalEquals(a.Kerbal, b.Kerbal));
 }
Пример #20
0
        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);
        }
Пример #21
0
 public void PausedUpdate(KerbalInfo kerbalInfo)
 {
     Screen.lockCursor = false;
 }