Exemple #1
0
 public void SendChangedCameraMode(WebJSON.CameraPos cameraPos)
 {
     if ((Application.platform == RuntimePlatform.WebGLPlayer || testMessages) && controller.LoadState == Controller.State.Finished)
     {
         Send(new WebJSON.Message()
         {
             Type   = WebJSON.MessageType.Camera,
             Camera = new WebJSON.CameraSettings()
             {
                 CameraPos = cameraPos
             }
         });
     }
 }
Exemple #2
0
    void Update()
    {
        MouseLookRMBEnabled = false;
        if (controller.LoadState != Controller.State.Finished && controller.LoadState != Controller.State.Error)
        {
            return;
        }
        if (!targetDirection.HasValue)
        {
            // Set target direction to the camera's initial orientation.
            targetDirection = transform.localRotation;
        }

        if (lastDebugCameraPos != debugCameraPos)
        {
            lastDebugCameraPos = debugCameraPos;
            controller.SetCameraPosition(debugCameraPos);
        }

        bool orthographic = cam.orthographic;

        if (Input.GetKeyUp(KeyCode.LeftShift) & _shifted)
        {
            _shifted = false;
        }

        if ((Input.GetKeyDown(KeyCode.LeftShift) & !_shifted && !Input.GetMouseButton(1)) |
            (Input.GetKeyDown(KeyCode.Escape) & MouseLookEnabled))
        {
            _shifted = true;

            if (!MouseLookEnabled)
            {
                MouseLookEnabled = true;
                Cursor.lockState = CursorLockMode.Locked;
                Cursor.visible   = false;
            }
            else
            {
                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    _shifted = false;
                }

                MouseLookEnabled = false;
                Cursor.lockState = CursorLockMode.None;
                Cursor.visible   = true;
            }
        }

        if (!MouseLookEnabled)
        {
            if (targetPos.HasValue)
            {
                if (Vector3.Distance(transform.position, targetPos.Value) < 0.4f)
                {
                    targetPos = null;
                }
                else
                {
                    transform.position = Vector3.Lerp(transform.position, targetPos.Value, Time.deltaTime * lerpFactor);
                }
            }
            if (targetRot.HasValue)
            {
                if (Mathf.Abs(Quaternion.Angle(transform.rotation, targetRot.Value)) < 10)
                {
                    targetRot = null;
                }
                else
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, targetRot.Value, Time.deltaTime * lerpFactor);
                }
            }

            Vector3 mouseDeltaOrtho = Input.mousePosition - lastMousePosition;
            lastMousePosition = Input.mousePosition;

            if (orthographic)
            {
                if (targetOrthoSize.HasValue)
                {
                    if (Mathf.Abs(targetOrthoSize.Value - cam.orthographicSize) < 0.04f)
                    {
                        targetOrthoSize = null;
                    }
                    else
                    {
                        cam.orthographicSize = Mathf.Lerp(cam.orthographicSize, targetOrthoSize.Value, Time.deltaTime * lerpFactor);
                    }
                }

                if (Input.GetMouseButton(1) || (Input.GetMouseButton(0)))
                {
                    StopLerp();

                    if (panStart == Vector3.zero)
                    {
                        panStart = Input.mousePosition;
                    }
                    Rect screenRect = new Rect(0, 0, Screen.width, Screen.height);

                    if (panning)
                    {
                        float xFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight;
                        float yFactor = Camera.main.orthographicSize * 2.0f / Camera.main.pixelHeight;

                        transform.Translate(Vector3.right * xFactor * -mouseDeltaOrtho.x, Space.Self);
                        transform.Translate(Vector3.up * yFactor * -mouseDeltaOrtho.y, Space.Self);
                    }
                    else if (Input.GetMouseButtonDown(1) || (Input.GetMouseButtonDown(0) && !controller.selector.IsSelecting) && screenRect.Contains(Input.mousePosition))                         // Only start panning if within game window when you click
                    {
                        panning = true;
                    }
                }
                else
                {
                    panStart = Vector3.zero;
                    panning  = false;
                }
                CameraControlsOrthographic();
            }
            else
            {
                // Right click: drag also works
                if (Input.GetMouseButton(1))
                {
                    MouseLookRMBEnabled = true;
                    StopLerp();

                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible   = false;

                    CalculateMouseLook(orthographic, false);

                    if (Input.GetKey(KeyCode.LeftShift))
                    {
                        _flySpeedShiftMultiplier = flySpeedShiftMultiplier;
                    }
                    else
                    {
                        _flySpeedShiftMultiplier = 1.0f;
                    }

                    CameraControlsPerspective();
                }

                if (Input.GetMouseButtonUp(1))
                {
                    Cursor.lockState         = CursorLockMode.None;
                    Cursor.visible           = true;
                    _flySpeedShiftMultiplier = 1.0f;
                }
            }
            CameraControlsSpeed();
        }
        else
        {
            StopLerp();
            //ensure these stay this way
            Cursor.lockState = CursorLockMode.Locked;
            Cursor.visible   = false;

            CalculateMouseLook(orthographic, true);

            //movement
            if (orthographic)
            {
                CameraControlsOrthographic();
            }
            else
            {
                CameraControlsPerspective();
            }
            CameraControlsSpeed();
        }
    }
Exemple #3
0
 public void UpdateDebugCameraPos(WebJSON.CameraPos cameraPos)
 {
     debugCameraPos     = cameraPos;
     lastDebugCameraPos = debugCameraPos;
 }