Пример #1
0
        protected override void OnInitialize()
        {
            base.OnInitialize();
            InternalCamera cam = new InternalCamera(Vector2.Zero, 0f, Vector2.One);

            EditorCamera = cam.GetComponent <Camera2D>();
        }
Пример #2
0
        protected override void OnInitialize()
        {
            bool headless = Screen.DisplayMode == DisplayMode.Decapitated || Screen.DisplayMode == DisplayMode.Headless;

            // Initialize input for player 1...
            InputManager.AddAxisInputs("PlayerVertical", new [] { Players.One },
                                       AxisInput.FromKeyboard(Keys.S, Keys.W),
                                       AxisInput.FromThumbStick(ThumbSticks.Left, ThumbSticksAxis.Y, 0.1f, true));

            InputManager.AddAxisInputs("PlayerHorizontal", new[] { Players.One },
                                       AxisInput.FromKeyboard(Keys.D, Keys.A),
                                       AxisInput.FromThumbStick(ThumbSticks.Left, ThumbSticksAxis.X, 0.1f));

            // Initialize input for player 2...
            InputManager.AddAxisInputs("PlayerVertical", new[] { Players.Two },
                                       AxisInput.FromKeyboard(Keys.G, Keys.T),
                                       AxisInput.FromThumbStick(ThumbSticks.Left, ThumbSticksAxis.Y, 0.1f, true));

            InputManager.AddAxisInputs("PlayerHorizontal", new[] { Players.Two },
                                       AxisInput.FromKeyboard(Keys.H, Keys.F),
                                       AxisInput.FromThumbStick(ThumbSticks.Left, ThumbSticksAxis.X, 0.1f));

            // Initialize networking...
            NetHelper.AddSpawnable("Player", typeof(NetPlayer));
            NetHelper.AddSpawnable("bouncy", typeof(BouncyBall));
            Network.OnServerStarted += SpawnStuff;
            Network.OnPeerConnected += peer => {
                if (Network.IsServer)
                {
                    NetHelper.Instantiate("Player", peer.GetUniqueID(), new Vector2(100, 100));
                    NetHelper.Instantiate("Player", peer.GetUniqueID(), new Vector2(100, 100));
                }
            };

            //SceneManager.SetCurrentScene("_DEMOS\\menu");
            SceneManager.SetCurrentScene("_DEMOS\\networktest");

            backToMenu = new BackButton();

            // Load the network test level, and start server if in fully-headless mode.
            if (headless)
            {
                SceneManager.SetCurrentScene("_DEMOS\\networktest");
                Network.StartServer(919, 920);
            }

            if (!Screen.IsFullHeadless)
            {
                Lighting.Ambient = new Color(0.1f, 0.1f, 0.1f);
            }

            new Cursor(Vector2.Zero, 0f, Vector2.One);

            if (!IsEditor)
            {
                GameObject camera = new InternalCamera(Vector2.Zero, 0f, Vector2.One);
            }
        }
Пример #3
0
 private void SetCameraToSeat()
 {
     if (InternalCamera.Instance == null)
     {
         Debug.LogError("InternalCamera was null");
         Debug.Log("Searching for camera: " + InternalCamera.FindObjectOfType <Camera>());
         return;
     }
     KerbalIva.transform.position = InternalCamera.Instance.transform.position;                                                               //forward;// FlightCamera.fetch.transform.forward;
     //previousRotation = InternalCamera.Instance.transform.rotation;// *Quaternion.AngleAxis(-90, InternalCamera.Instance.transform.right);
     previousRotation = Quaternion.AngleAxis(-90, InternalCamera.Instance.transform.right) * InternalCamera.Instance.transform.localRotation; // Fixes "unbuckling looking at feet"
 }
        public void UpdateCameraProperties(float camPitch, float camYaw, float camZoom, float camSensitivity)
        {
            switch (CameraManager.Instance.currentCameraMode)
            {
            case CameraManager.CameraMode.Flight:
            {
                FlightCamera.CamHdg   += camYaw * camSensitivity;
                FlightCamera.CamPitch += -camPitch * camSensitivity;
                FlightCamera.fetch.SetDistance(FlightCamera.fetch.Distance + camZoom * flightZoomStep);
                break;
            }

            case CameraManager.CameraMode.Map:
            {
                PlanetariumCamera cam = PlanetariumCamera.fetch;
                cam.camHdg   += camYaw * camSensitivity;
                cam.camPitch += -camPitch * camSensitivity;
                cam.SetDistance(Utility.Clamp(cam.Distance + (cam.Distance * camZoom * mapZoomStep), cam.minDistance, cam.maxDistance));
                break;
            }

            case CameraManager.CameraMode.IVA:
            case CameraManager.CameraMode.Internal:
            {
                //Hack: access private field that holds pitch/yaw in degrees before being applied to the camera.
                if (this.ivaCamFieldsLoaded)
                {
                    InternalCamera cam = InternalCamera.Instance;
                    ivaPitchField.SetValue(cam, (float)ivaPitchField.GetValue(cam) + camPitch * camSensitivity * ivaPanStep);
                    ivaYawField.SetValue(cam, (float)ivaYawField.GetValue(cam) + camYaw * camSensitivity * ivaPanStep);
                }
                if (camZoom != 0)
                {
                    // InternalCamera.Instance.SetFOV(Utility.Clamp(InternalCamera.Instance.camera.fieldOfView + camZoom * ivaFovStep, ivaFovMin, ivaFovMax));
                }
                break;
            }

            default:
                Debug.LogWarning("AFBW - Unsupported CameraMode: " + CameraManager.Instance.currentCameraMode.ToString());
                break;
            }
        }
Пример #5
0
        // Old IVA cam updater. It takes exclusive control of the camera and doesn't reset on vehicle change.
        // It also needs to update rotation on EVERY Update() call or Squad will overwrite it before render.
        // Inspiration from: https://github.com/pizzaoverhead/KerbTrack/blob/master/KerbTrack/KerbTrack.cs#L402-459
        private void OldUpdateIVACamera(float camPitch, float camYaw, float camZoom, float camSensitivity)
        {
            float fovMaxIVA   = 90f;
            float fovMinIVA   = 10f;
            float pitchMaxIVA = 60f;
            float pitchMinIVA = -30f;
            float maxRot      = 60f;
            float IVAscale    = 10.0f;

            float pitchChange = Mathf.Clamp(camPitch * IVAscale * Time.deltaTime * 30f, pitchMinIVA, pitchMaxIVA);
            float yawChange   = Mathf.Clamp(camYaw * IVAscale * Time.deltaTime * 30f, -maxRot, maxRot);

            InternalCamera cam = InternalCamera.Instance;

            cam.transform.localRotation          *= Quaternion.Euler(-pitchChange, yawChange, 0);
            FlightCamera.fetch.transform.rotation = InternalSpace.InternalToWorld(cam.transform.rotation);
            Debug.Log("Cam rotation: " + cam.transform.localRotation.ToString());

            if (camZoom != 0)
            {
                // InternalCamera.Instance.SetFOV(Utility.Clamp(InternalCamera.Instance.camera.fieldOfView + camZoom * IVAscale, fovMinIVA, fovMaxIVA));
            }
        }
Пример #6
0
        public void cameraRotationCallback(byte ID, object Data)
        {
            //Debug.Log("Camera Rotation Callback");
            newCameraRotation = KerbalSimpitUtils.ByteArrayToStructure <CameraRotationalStruct>((byte[])Data);
            // Bit fields:
            // pitch = 1
            // roll = 2
            // yaw = 4
            switch (cameraManager.currentCameraMode)
            {
            case CameraManager.CameraMode.Flight:
                FlightCamera flightCamera = FlightCamera.fetch;
                if ((newCameraRotation.mask & (byte)1) > 0)
                {
                    myCameraRotation.pitch = newCameraRotation.pitch;
                    // Debug.Log("Rotation Message Seen");
                    float newPitch = flightCamera.camPitch + (myCameraRotation.pitch * flightCameraPitchMultiplier);
                    if (newPitch > flightCamera.maxPitch)
                    {
                        flightCamera.camPitch = flightCamera.maxPitch;
                    }
                    else if (newPitch < flightCamera.minPitch)
                    {
                        flightCamera.camPitch = flightCamera.minPitch;
                    }
                    else
                    {
                        flightCamera.camPitch = newPitch;
                    }
                }
                if ((newCameraRotation.mask & (byte)2) > 0)
                {
                    myCameraRotation.roll = newCameraRotation.roll;
                }
                if ((newCameraRotation.mask & (byte)4) > 0)
                {
                    myCameraRotation.yaw = newCameraRotation.yaw;
                    // Debug.Log("Yaw Message Seen");
                    float newHdg = flightCamera.camHdg + (myCameraRotation.yaw * flightCameraYawMultiplier);
                    flightCamera.camHdg = newHdg;
                }
                if ((newCameraRotation.mask & (byte)8) > 0)
                {
                    myCameraRotation.zoom = newCameraRotation.zoom;
                    float newZoom = flightCamera.Distance + (myCameraRotation.zoom * flightCameraZoomMultiplier);
                    if (newZoom > flightCamera.maxDistance)
                    {
                        newZoom = flightCamera.maxDistance;
                    }
                    else if (newZoom < flightCamera.minDistance)
                    {
                        newZoom = flightCamera.minDistance;
                    }
                    flightCamera.SetDistance(newZoom);
                }
                break;

            case CameraManager.CameraMode.IVA:
            case CameraManager.CameraMode.Internal:
                Kerbal ivaKerbal = cameraManager.IVACameraActiveKerbal;

                if (ivaKerbal == null)
                {
                    Debug.Log("Kerbal is null");
                }

                InternalCamera ivaCamera = InternalCamera.Instance;
                ivaCamera.mouseLocked = false;

                if (ivaCamera == null)
                {
                    Debug.Log("IVA Camera is null");
                }
                else
                {
                    float newPitch = (float)ivaPitchField.GetValue(ivaCamera);
                    float newYaw   = (float)ivaYawField.GetValue(ivaCamera);

                    if ((newCameraRotation.mask & (byte)1) > 0)
                    {
                        myCameraRotation.pitch = newCameraRotation.pitch;
                        //Debug.Log("IVA Rotation Message Seen");
                        newPitch += (myCameraRotation.pitch * ivaCameraMultiplier);

                        if (newPitch > ivaCamera.maxPitch)
                        {
                            newPitch = ivaCamera.maxPitch;
                        }
                        else if (newPitch < ivaCamera.minPitch)
                        {
                            newPitch = ivaCamera.minPitch;
                        }
                    }
                    if ((newCameraRotation.mask & (byte)2) > 0)
                    {
                        myCameraRotation.roll = newCameraRotation.roll;
                    }
                    if ((newCameraRotation.mask & (byte)4) > 0)
                    {
                        myCameraRotation.yaw = newCameraRotation.yaw;
                        //Debug.Log("IVA Yaw Message Seen");
                        newYaw += (myCameraRotation.yaw * ivaCameraMultiplier);
                        if (newYaw > 120f)
                        {
                            newYaw = 120f;
                        }
                        else if (newYaw < -120f)
                        {
                            newYaw = -120f;
                        }
                    }
                    //Debug.Log("Before set angle");
                    if (this.ivaCamFieldsLoaded)
                    {
                        ivaPitchField.SetValue(ivaCamera, newPitch);
                        ivaYawField.SetValue(ivaCamera, newYaw);
                        // Debug.Log("Camera vector: " + ivaCamera.transform.localEulerAngles.ToString());
                        FlightCamera.fetch.transform.rotation = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.rotation);
                    }
                }
                break;

            default:
                Debug.Log("Kerbal Simpit does not support this camera mode: " + cameraManager.currentCameraMode.ToString());
                break;
            }
        }
Пример #7
0
        public void UpdateCurrentPart()
        {
            if (InternalCamera.Instance == null)
            {
                Debug.LogError("InternalCamera was null");
                Debug.Log("Searching for camera: " + InternalCamera.FindObjectOfType <Camera>());
                return;
            }

            if (_previousCameraPosition == InternalCamera.Instance.transform.position)
            {
                return;
            }
            //Debug.Log("###########################");
            _previousCameraPosition = InternalCamera.Instance.transform.position;
            Vector3 camPos   = InternalSpace.InternalToWorld(InternalCamera.Instance.transform.position);
            Part    lastPart = CurrentPart;

            // Part colliders are larger than the parts themselves and overlap.
            // Find which of the containing parts we're nearest to.
            List <Part> possibleParts = new List <Part>();

            if (CurrentPart != null) // e.g. on part destroyed.
            {
                if (PartBoundsCamera(CurrentPart))
                {
                    //Debug.Log("# Adding previous currentpart.");
                    possibleParts.Add(CurrentPart);
                }
                // Check all attached parts.
                if (CurrentPart.parent != null && PartBoundsCamera(CurrentPart.parent))
                {
                    //Debug.Log("# Adding parent " + CurrentPart.parent);
                    possibleParts.Add(CurrentPart.parent);
                }
                foreach (Part c in CurrentPart.children)
                {
                    if (PartBoundsCamera(c))
                    {
                        //Debug.Log("# Adding child " + c);
                        possibleParts.Add(c);
                    }
                }
            }
            if (possibleParts.Count == 0)
            {
                //Debug.Log("# Zero connected parts found, checking everything.");
                foreach (Part p in FlightGlobals.ActiveVessel.parts)
                {
                    if (PartBoundsCamera(p))
                    {
                        //Debug.Log("# Adding vessel part " + p);
                        possibleParts.Add(p);
                    }
                }
            }

            if (possibleParts.Count == 0)
            {
                //Debug.Log("# No potential parts found");
                return;
            }

            if (possibleParts.Count == 1)
            {
                //Debug.Log("# Only one part found: " + possibleParts[0]);
                CurrentPart = possibleParts[0];
                if (CurrentPart != lastPart)
                {
                    OnIvaPartChanged.Fire(CurrentPart);
                }

                /*else
                 *  Debug.Log("# Same part as before: " + CurrentPart + " at " + CurrentPart.transform.position);*/
                return;
            }

            float minDistance = float.MaxValue;
            Part  closestPart = null;

            //Debug.Log("# Checking " + possibleParts.Count + " possibilities.");
            foreach (Part pp in possibleParts)
            {
                // Raycast from the camera to the centre of the collider.
                // TODO: Figure out how to deal with multi-collider parts.
                Vector3    c         = pp.collider.bounds.center;
                Vector3    direction = c - camPos;
                Ray        ray       = new Ray(camPos, direction);
                RaycastHit hitInfo;
                if (!pp.collider.Raycast(ray, out hitInfo, direction.magnitude))
                {
                    //Debug.Log("# Raycast missed part from inside: " + pp);
                    // Ray didn't hit the collider => we are inside the collider.
                    float dist = Vector3.Distance(pp.collider.bounds.center, camPos);
                    if (dist < minDistance)
                    {
                        closestPart = pp;
                        minDistance = dist;
                    }

                    /*else
                     *  Debug.Log("# Part was further away: " + minDistance + " vs part's " + dist);*/
                }

                /*else
                 *  Debug.Log("# Raycast hit part from outside: " + pp);*/
            }
            if (closestPart != null)
            {
                //Debug.Log("# New closest part found: " + closestPart);
                CurrentPart = closestPart;
                if (CurrentPart != lastPart)
                {
                    OnIvaPartChanged.Fire(CurrentPart);
                }

                /*else
                 *  Debug.Log("# Same part as before: " + CurrentPart + " at " + CurrentPart.transform.position);*/
            }

            /*else
             *  Debug.Log("# No closest part found.");*/
            // Keep the last part we were inside as the current part: We could be transitioning between hatches.
            // TODO: Idendify/store when we are outside all parts (EVA from IVA?).
        }