I have various 2D panels built to create fake 3D objects (cubes, for example). I need to add some sort of depth of field to the project, because I want to highlight the objects which are near the camera and fade out objects which are further away. However, Depth Of Field blurs all the objects separately, so it doesn't blur the corners correctly. Is there any way to fix it or is there some alternative method to do depth of field?
There is a Depth of Field filter - but that's an entirely different effect designed for "Tilt-Shift" effect or "miniaturization".
The Depth of field you're talking about is a function of the Camera and it works like it's supposed to, but the trick is getting the camera set up to represent the kind of defocus you're looking for.
First of all, you have to turn it on from the Render Menu > Depth of Field. You have to have a Camera added. Also realize that in the Active Camera View -- you ARE the camera's viewpoint. So, to adjust the Depth of Field of your scene, you'll need to go into Perspective view (or one of the other "views") so you can see the camera's 3d scene wireframes. Select the Camera in layers and in the Inspector > Camera > Depth of Field, adjust the settings.
Use the Focus offset to set your "plane of focus" (you can split the canvas into Perspective and Active camera views simultaneously so you can watch the focus offsets and see the end result at that same time.) You can expand the focus depth of field (like "stopping down" a camera lens) with Near Focus (increasing this value will pull back the range of focus towards the camera) and Far Focus (increasing this value will push the range away from the camera.) Don't check Infinite Focus - it's like turning off the effect.
The Gaussian filter is faster and I generally prefer it to Defocus. You can check that out for yourself. Try setting the Depth to Planar will soften the effect on "near focus" edges.