
This also works for tiling background images, repeating them if a very wide camera viewport exceeds the image's aspect ratio.Using UnityEngine using UnityEditor using System.Collections using using UnityEditorInternal // for InternalSpriteUtility using System. Uv.x = (v.uv.x - 0.5f) * conversion + 0.5f Property to set or get the size to render when the SpriteRenderer.drawMode is set to SpriteDrawMode.Sliced or SpriteDrawMode.Tiled.
(Delete the 0.5 shifts if you prefer to anchor at left) So, I crated a Prefab GameObject containing RectTransform and SpriteRenderer, and got the width and height as below: GameObject twoSide Instantiate (Resources.Load (mFilePath + 'Locater')) as GameObject twoSide.GetComponentTexturePacker is a tool that specializes in creating sprite sheets. Scale from center, rather than from the corner. 1 Answer Sorted by: 2 This is as it should be - no bug -) TexturePacker has 2 crop modes in Unity - to remove transparency around the sprites which consumes memory and GPU. (is from a game) but Unity cant take good the size of the boxes and i dont know. O.vertex = float4(v.vertex.xy * 2.0f, 0.5f, 1) įloat cameraAspect = _ScreenParams.x * (_ScreenParams.w - 1.0f) įloat invTextureAspect = _MainTex_TexelSize.w * _MainTex_TexelSize.x įloat conversion = invTextureAspect * cameraAspect Whatever you choose, though, ensure you pixels per unit setting allows your expected resolution to make the most of your sprites.

how big your sprites should be is purely up to what you feel is good for your game. _PreserveAspect ("Preserve Aspect Ratio", Float) = 1 Derekloffin Joined: Posts: 322 Haven't got much a nose for ascetics, but I can give my opinion: 1.

I'm assuming here that your sprite's pivot is its center, placed at (0, 0, depth) in the camera's coordinate system, and that the aspect ratio of the sprite is known to be as wide or wider than the widest supported resolution so it fills the frame.Īlternatively, as I mentioned previously, you could make a shader that does this automatically for a standard Unity quad with vertices running from (-0.5, -0.5) to (0.5, 0.5) by transforming them to the viewport corners: Shader "Unlit/FillCameraFrame" This matches the height of the sprite to the height the camera can "see" at that depth. How many times bigger (or smaller) is the height we want to fill? You could also use Sprite.bounds for this.įloat spriteHeight = in world space units, at our target depth?įloat visibleHeightAtDepth = depth * Mathf.Tan(halfFovRadians) * 2f I really don’t want to have to redo all the pivot points every time I decide to add a sprite to the sheet. or I get the sprite width and height and not the padded texture size. tpsheet file which overrides any trimming and pivot points I changed before I updated the sprite sheet. How high is it from top to bottom of the view frustum, I’m using TexturePacker to put together my sprite sheets, but every time I publish an updated sprite sheet, it produces a. Here's how you can compute the necessary scaling factor: // Angle the camera can see above the center.įloat halfFovRadians = camera.fieldOfView * Mathf.Deg2Rad / 2f _ = Vector3.one * scaleFactor įor good measure, here is the what the sprite's game object and camera look like in the inspector: private SpriteRenderer _spriteRenderer įloat fovRadians = Mathf.Deg2Rad * _camera.fieldOfView įloat visibleHeightAtDepth = * Mathf.Tan(fovRadians) * 2f įloat spriteHeight = _įloat scaleFactor = visibleHeightAtDepth / spriteHeight It has ability to import atlas exported by texture packer and use it frames, take a look here: UIAtlas. So to get the width of these sprites i am using tileWidth (int)tileSet 0. TexturePacker has 2 crop modes in Unity - to remove transparency around the sprites which consumes memory and GPU. 1 Answer Sorted by: 0 It would be easiest if you use some framework for UI, for example NGUI from Unit圓d Asset Store. I've also attached the following Script to the child gameobject: private Camera _camera 13 I am trying to create a row out of some square sprites I have. Default: Fit to width Fit to height Keep original size (Press enter to. I've made a child gameObject of the MainCamera and attached my sprite to it. First convert the image into sprite in unity editor, then you can load that at. To remedy this, I'm resizing my sprite by doing the following: I have made the background sprite a child of my MainCamera & dragged it further back on the Z-axis so that it is rendered behind everything else in the scene.īecause I have dragged it so far back in the scene, it no longer covers the entirety of my game screen.

My game's resolution is 1920 x 1080, and I have a background sprite that is also 1920 x 1080.
