How do I lock the width on an orthographic camera?

I’m trying to achieve this:

iphone5
49120-iphone5.png
ipad
49119-ipad.png

The problem is that when the resolution changes, it is locking the height and expanding the width to the new ratio.

I have seen this solution:

  float aspectRatio = (float)Screen.width / (float)Screen.height;
  float cameraHeight = WORLD_WIDTH / aspectRatio;
  camera.orthographicSize = cameraHeight/2f;

The problem with Screen.width does not work in the Editor. It gives me the size of the entire editor window and has nothing to do with the resolution set in the game window.

I would like to be able to preview what the game will look like at different resolutions and not just hope things look fine on all devices.

Oddly, the CanvasScaler can already do this. Does anyone know a way to achieve this so that I can preview different resolutions in the editor? Is there a way to get the world

this is what I ended up with:

	int cameraHeight = 178;
	int fixedWidth = 1136;
	float desiredAspect = 16f/9f;
	float aspect = Camera.main.aspect;
	float ratio =  desiredAspect / aspect;
	Camera.main.orthographicSize = cameraHeight * ratio;

cameraHeight was just the height that I happened to be working in. Seems very hacky. Is there a better way?

the above script seems to handle it just fine. I put it in a call that is run once outside the editor and run constantly in the editor. (fixedWidth was not actually needed). My camera height happened to be really large before. I made it 11.36 because all the sprite stuff was 100 pixels to units by default, and i figured I should just divide 1136 by 100 and I’d hopefully be pixel perfect. If there are better ways to do this then let me know.

In a side note, using Canvas and it’s auto-scaling solutions did not solve the problem and had a noticeable performance difference.

 int cameraHeight = 11.36;
 float desiredAspect = 16f/9f;
 float aspect = Camera.main.aspect;
 float ratio =  desiredAspect / aspect;
 Camera.main.orthographicSize = cameraHeight * ratio;