How to make a Lock-On camera?

I’m trying to make a camera that orbits the player in 3D space while still facing an enemy. The poblem is, I want the camera to still be vertically flexible (the player can move it with the mouse).
With other words: I want the camera to turn the way the player faces the enemy on the XZ axis, while maintaining it’s rotation around the X axis (vertical orbiting).

// Rotation - movement of the mouse, Distance - length of the offset.
Vector3 CalculatePosition(float rotationX, float rotationY, float distance)
{
Vector3 direction = new Vector3(0, 0, -distance);
Quaternion rotation = Quaternion.Euler(rotationX, rotationY, 0);

    if(lockOnTarget == null)
        return parentingObject.position + rotation * direction;

    Vector3 dir = lockOnTarget.position - targetLookAt.position;
    dir.Normalize();

    rotation = Quaternion.LookRotation(dir);

    return parentingObject.position + rotation * direction;
}

targetLookAt - is an empty game object around which the camera acualy orbits as well as looks at.

I have problems combining the “dir” vector with the rotationY of the camera.

Just set the Camera.LookAt() to the lockon target and move the target.