This window/tool helps you to configure your camera to fit correctly the SpriteRenderer on your game view.
- Open the Orthographic Camera Fitter window:
- Tools -> Fenikkel -> Orthographic Camera Fitter
- Fill the fields:
- Reference height: It should be the resolution of the height of the artist's project (.psd, .ai, etc) that never changes between the different resolutions of the different aspect ratios.
- Pixels per unit: How many pixels in the sprite correspond to one unit in the world. You can see the value of your images in the import settings. By default is 100. You should have the same value in ALL your sprites to let this configuration work correctly.
- Camera: Camera component to use for the setup. Usually your Main Camera.
- Click on "Configure camera": This will change the projection and size fields of the selected camera component.
It's important to have the script inside of a folder called "Editor"
A 2D artist is working on Photoshop project with a canvas resolution of 2048 x 1536.
Open the Orthographic Camera Fitter window and set the "Pixels per unit" to the same as your sprites import settings configuration (by default 100) and set the "Reference height" to 1536.
If you are doing a 2D project and you are gonna use SpriteRenderer, you probably want your sprites to have (by default) the same size as they have in the 2D artist project (photoshop, illustrator, etc).
To accomplish that, first of all, you need to import all your sprites with the same pixels per unit value in the import configuration. By default it's 100.
Then, you need to change the fields Projection and Size of your camera component to make your SpriteRenderer fit perfectly like the 2D artist project. The Projection must be set to Orthographic. The Size depends on the formula (Reference height / Pixels per unit) / 2. The variable "Reference height" it's the height resolution that the 2D artist was working with. And the variable "Pixels per unit" it's the same as your sprites import configuration.
Now your project is ready to maintain the same sprite size as the 2D artist designed. Also, you can now switch to any landscape resolution or aspect ratio and the game view will only be expanded or reduced from the sides. The height will remain perfectly adjusted.
This solution only works for landscape or squared games. If your game it's portrait, you probably want to use the PixelPerfectCamera component. This will have your orthographic camera size adapting to different resolutions but it will not respect the size of the Sprite between resolutions.
- Any Unity version
- Any pipeline (Build-in, URP, HDRP, etc)
⭐ Star if you like it
❤️️ Follow me for more