// 垂直旋转
 public void RotateV(float val)
 {
     if (lookAt == null || val == 0)
     {
         return;
     }
     _eulerAnglesX -= val;
     _eulerAnglesX  = MathTools.ClampAngle(_eulerAnglesX, minVerticalRotAngle,
                                           maxVerticalRotAngle);
 }
Exemplo n.º 2
0
    void LateUpdate()
    {
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            settings.isAttached = false;
        }

        if (IsAttached())
        {
            settings.position = target.transform.position;
        }

        if (settings.isEnabled)
        {
            if (!Input.GetMouseButton(1))
            {
                settings.rotation.x += Input.GetAxis("Mouse Y") * settings.speed.x;
                settings.rotation.y += Input.GetAxis("Mouse X") * settings.speed.y;
                settings.rotation.x  = MathTools.ClampAngle(settings.rotation.x, settings.xMinLimit, settings.xMaxLimit);
            }

            var distRaw = -Input.GetAxis("Mouse ScrollWheel") * settings.speed.z;

            if (Input.GetKey(KeyCode.UpArrow))
            {
                distRaw -= settings.speed.z * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.DownArrow))
            {
                distRaw += settings.speed.z * settings.keyFactor * Time.deltaTime;
            }

            settings.distance = Mathf.Max(settings.distance + distRaw, settings.minDistance);
        }

        if (IsRotateWithTarget())
        {
            settings.rotation    = target.rotation.eulerAngles;
            settings.rotation.z  = 0;
            settings.rotation.x += 5;
        }

        var quatRot = Quaternion.Euler(settings.rotation);

        if (settings.isEnabled)
        {
            var shift = Vector3.zero;

            if (Input.GetKey(KeyCode.W))
            {
                shift.z += settings.speed.z * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.S))
            {
                shift.z -= settings.speed.z * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.A))
            {
                shift.x += settings.speed.x * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.D))
            {
                shift.x -= settings.speed.x * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.Q))
            {
                shift.y -= settings.speed.y * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKey(KeyCode.E))
            {
                shift.y += settings.speed.y * settings.keyFactor * Time.deltaTime;
            }

            if (Input.GetKeyDown(KeyCode.T))
            {
                settings.rotateWithTarget = !settings.rotateWithTarget;
            }

            if (shift != Vector3.zero)
            {
                settings.position  += quatRot * shift;
                settings.isAttached = false;
            }
        }

        transform.rotation = quatRot;
        transform.position = quatRot * new Vector3(0.0f, 0.0f, -settings.distance) + settings.position;
    }