Пример #1
0
 public void Update()
 {
     if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA)
     {
         if (_lastCameraMode == CameraManager.CameraMode.IVA)
         {
             // Switching away from IVA.
             //InputLockManager.RemoveControlLock("FreeIVA");
             // Return the kerbal to its original seat.
             TargetedSeat = ActiveKerbal.seat;
             Buckle();
         }
     }
     else
     {
         // In IVA.
         if (_lastCameraMode != CameraManager.CameraMode.IVA)
         {
             // Switching to IVA.
             FreeIva.EnableInternals();
             SetCameraToSeat();
             InternalCollider.HideAllColliders();
         }
         GetInput();
     }
     _lastCameraMode = CameraManager.Instance.currentCameraMode;
 }
Пример #2
0
        public void Update()
        {
            if (CameraManager.Instance.currentCameraMode != CameraManager.CameraMode.IVA)
            {
                if (_lastCameraMode == CameraManager.CameraMode.IVA) // Switching away from IVA.
                {
                    InputLockManager.RemoveControlLock("FreeIVA");

                    // Return the kerbal to its original seat.
                    TargetedSeat = ActiveKerbal.seat;
                    if (!buckled)
                    {
                        Buckle();
                    }
                }
            }
            else
            {
                // In IVA.
                if (_lastCameraMode != CameraManager.CameraMode.IVA)
                {
                    // Switching to IVA.
                    FreeIva.EnableInternals();
                    UpdateActiveKerbal();//false);
                    SetCameraToSeat();
                    InternalCollider.HideAllColliders();
                }

                // Check if we're changing crew member using the 'V' key.
                if (GameSettings.CAMERA_NEXT.GetKeyDown())
                {
                    _changingCurrentIvaCrew = true;
                }
                else
                {
                    if (_changingCurrentIvaCrew)
                    {
                        UpdateActiveKerbal();//false);
                        _changingCurrentIvaCrew = false;
                    }
                }

                // TODO: Doesn't get mouse input when in FixedUpdate.
                // Split this out to flags set in Update and acted upon in FixedUpdate.
                GetInput();

                /*FreeIva.InitialPart.Events.Clear();
                 * if (_transferStart != 0 && Planetarium.GetUniversalTime() > (0.25 + _transferStart))
                 * {
                 *  FlightGlobals.ActiveVessel.SpawnCrew();
                 *  GameEvents.onVesselChange.Fire(FlightGlobals.ActiveVessel);
                 *  InternalCamera.Instance.transform.parent = ActiveKerbal.KerbalRef.eyeTransform;
                 *  _transferStart = 0;
                 * }*/
            }
            _lastCameraMode = CameraManager.Instance.currentCameraMode;
        }
Пример #3
0
        //static bool _initialised = false;
        public static void EnableInternals()
        {
            try
            {
                //if (_initialised) return;

                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                {
                    if (p.internalModel == null)
                    {
                        p.CreateInternalModel();
                    }
                    if (p.internalModel != null)
                    {
                        p.internalModel.SetVisible(true);
                        PropHatch.AddPropHatches(p.internalModel);
                        //PrintInternals(p);
                    }
                }

                // TODO
                InternalCollider.HideAllColliders();
                // TODO
                Hatch.InitialiseAllHatchesClosed();

                //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // Colliders, hatches and hatch props are all unhidden by this.
                //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


                //_initialised = true;
            }
            catch (Exception ex)
            {
                Debug.LogError("[FreeIVA] Error enabling internals: " + ex.Message + ", " + ex.StackTrace);
            }
        }
Пример #4
0
        private static void ColliderGui()
        {
            // TODO: Automatically add colliders to selected props using renderer bounds?

            if (GUILayout.Button((showColliderGui ? "Hide" : "Show") + " collider configuration"))
            {
                showColliderGui = !showColliderGui;
            }
            if (!showColliderGui)
            {
                InternalCollider.HideAllColliders();
                return;
            }


            GUILayout.BeginHorizontal();
            KerbalIva.KerbalCollider.collider.enabled = !GUILayout.Toggle(!KerbalIva.KerbalCollider.collider.enabled, "NoClip");
            bool helmet = KerbalIva.WearingHelmet;

            KerbalIva.WearingHelmet = GUILayout.Toggle(KerbalIva.WearingHelmet, "Helmet");
            if (helmet != KerbalIva.WearingHelmet)
            {
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Print collision layers"))
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("                    1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3");
                sb.Append("0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1");
                for (int i = 0; i < 32; i++)
                {
                    sb.Append("\r\n");
                    if (i < 10)
                    {
                        sb.Append(" ");
                    }
                    sb.Append(i).Append("\t");
                    for (int j = 0; j < 32; j++)
                    {
                        sb.Append(Physics.GetIgnoreLayerCollision(i, j) ? "T " : "F ");
                    }
                }
                Debug.Log(sb.ToString());
            }

            if (GUILayout.Button("Create new collider"))
            {
                InternalCollider col = new InternalCollider();
                col.Scale = new Vector3(0.5f, 0.5f, 0.5f);
                col.Instantiate(CurrentPart, _primitiveType);
                col.IvaGameObject.name = "Test collider";
                CurrentModuleFreeIva.InternalColliders.Add(col);
                _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1;
            }
            if (GUILayout.Button("Stop all movement"))
            {
                foreach (var col in CurrentModuleFreeIva.InternalColliders)
                {
                    col.IvaGameObject.rigidbody.velocity        = Vector3.zero;
                    col.IvaGameObject.rigidbody.angularVelocity = Vector3.zero;
                }
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Sphere, "Sphere"))
            {
                _primitiveType = PrimitiveType.Sphere;
            }
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Capsule, "Capsule"))
            {
                _primitiveType = PrimitiveType.Capsule;
            }
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cylinder, "Cylinder"))
            {
                _primitiveType = PrimitiveType.Cylinder;
            }
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Cube, "Cube"))
            {
                _primitiveType = PrimitiveType.Cube;
            }
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Plane, "Plane"))
            {
                _primitiveType = PrimitiveType.Plane;
            }
            if (GUILayout.Toggle(_primitiveType == PrimitiveType.Quad, "Quad"))
            {
                _primitiveType = PrimitiveType.Quad;
            }
            GUILayout.EndHorizontal();

            InternalCollider c = null;

            if (CurrentModuleFreeIva.InternalColliders.Count == 0)
            {
                GUILayout.Label("No colliders");
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Previous collider"))
                {
                    _colliderIndex--;
                }
                if (GUILayout.Button("Next collider"))
                {
                    _colliderIndex++;
                }
                GUILayout.EndHorizontal();
                if (_colliderIndex >= CurrentModuleFreeIva.InternalColliders.Count)
                {
                    _colliderIndex = 0;
                }
                if (_colliderIndex < 0)
                {
                    _colliderIndex = CurrentModuleFreeIva.InternalColliders.Count - 1;
                }
                GuiUtils.label("Current collider", _colliderIndex + 1);
                c = CurrentModuleFreeIva.InternalColliders[_colliderIndex];
                GuiUtils.label("Collider (" + (_colliderIndex + 1) + "/" + CurrentModuleFreeIva.InternalColliders.Count + ")", c.Name);
            }
            if (c == null)
            {
                return;
            }

            if (GUILayout.Button("Destroy collider"))
            {
                CurrentModuleFreeIva.InternalColliders.Remove(c);
                c.IvaGameObject.DestroyGameObject();
            }

            GUILayout.BeginHorizontal();
            c.IvaGameObject.collider.enabled = GUILayout.Toggle(c.IvaGameObject.collider.enabled, "Enabled");
            bool wasVisible = c.Visible;
            bool v          = GUILayout.Toggle(wasVisible, "Visible");

            if (v != wasVisible)
            {
                c.Visible = v;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Position X");

            float xPos = float.Parse(GUILayout.TextField(c.LocalPosition.x.ToString()));

            GUILayout.Label("Position Y");
            float yPos = float.Parse(GUILayout.TextField(c.LocalPosition.y.ToString()));

            GUILayout.Label("Position Z");
            float zPos = float.Parse(GUILayout.TextField(c.LocalPosition.z.ToString()));

            if (xPos != c.LocalPosition.x || yPos != c.LocalPosition.y || zPos != c.LocalPosition.z)
            {
                //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>();
                //if (currentJoint != null) Destroy(currentJoint);
                c.LocalPosition = new Vector3(xPos, yPos, zPos);
                //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>();
                //currentJoint.connectedBody = CurrentPart.collider.rigidbody;
                c.IvaGameObject.rigidbody.velocity        = Vector3.zero;
                c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Scale X");
            float xSc = float.Parse(GUILayout.TextField(c.Scale.x.ToString()));

            GUILayout.Label("Scale Y");
            float ySc = float.Parse(GUILayout.TextField(c.Scale.y.ToString()));

            GUILayout.Label("Scale Z");
            float zSc = float.Parse(GUILayout.TextField(c.Scale.z.ToString()));

            if (xSc != c.Scale.x || ySc != c.Scale.y || zSc != c.Scale.z)
            {
                //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>();
                //if (currentJoint != null) Destroy(currentJoint);
                c.Scale = new Vector3(xSc, ySc, zSc);
                //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>();
                //currentJoint.connectedBody = CurrentPart.collider.rigidbody;
                c.IvaGameObject.rigidbody.velocity        = Vector3.zero;
                c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Rotation X");
            float xRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.x.ToString()));

            GUILayout.Label("Rotation Y");
            float yRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.y.ToString()));

            GUILayout.Label("Rotation Z");
            float zRot = float.Parse(GUILayout.TextField(c.Rotation.eulerAngles.z.ToString()));

            if (xRot != c.Rotation.eulerAngles.x || yRot != c.Rotation.eulerAngles.y || zRot != c.Rotation.eulerAngles.z)
            {
                //currentJoint = c.IvaGameObject.GetComponent<FixedJoint>();
                //if (currentJoint != null) Destroy(currentJoint);
                c.Rotation = Quaternion.Euler(xRot, yRot, zRot);
                //currentJoint = c.IvaGameObject.AddComponent<FixedJoint>();
                //currentJoint.connectedBody = CurrentPart.collider.rigidbody;
                c.IvaGameObject.rigidbody.velocity        = Vector3.zero;
                c.IvaGameObject.rigidbody.angularVelocity = Vector3.zero;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GuiUtils.label("Velocity", c.IvaGameObject.rigidbody.velocity.magnitude);
            GuiUtils.label("Angular velocity", c.IvaGameObject.rigidbody.angularVelocity.magnitude);
            GUILayout.EndHorizontal();
        }