

This value is the height of the Texture at the highest resolution that PlayerSettings.mipStripping allows. So you can use it like this: public Image image Height of the Texture in pixels (Read Only). RectTransform ImageRect = img.GetComponent() įloat _bodyWidth = desiredWidth = default ? : desiredWidth įloat _imageWidth = (float) įloat _imageHeight = (float) įloat _ratio = _imageWidth / _imageHeight įloat _expectedHeight = _bodyWidth / _ratio Public static float GetDesiredHeigth(this Image img, float desiredWidth = default) (I use Assets/Scripts/Importers) Export an atlas and texture from TexturePacker into your project. Assigning a Sprite to SpriteRenderer.sprite when it is null will also set the SpriteRenderer.size value to the Sprites width and height. Usage: Add the script somewhere inside your Unity project Assets folder. Your find the script in the attachments ( View attachment 78663 ). Property to set or get the size to render when the SpriteRenderer.drawMode is set to SpriteDrawMode.Sliced or SpriteDrawMode.Tiled. / Get the height of an image according to the rendered sprite and the desired width(if is not specified, it will take the width of the own image's recTransform) Where spriteBatch is the SpriteBatch and frame is a Sprite x, y, width and height are the same as you would use in spriteBatch.draw(frame, x, y, width, height) To only draw the top half of a sprite (as if the sprite was standing in a liquid, for example) you would set the height, the texture region height, and include a slight adjustment to. 10 Texture Packer Importer If you watch the video, you see, that if you are clicking on an atlas you have two options: Process to Mesh Process to Prefab For the new introduced texture type 'Sprite' in Unity 4.3 I wrote a third import option, which is called 'Process to Sprites'. Default: Fit to width Fit to height Keep original size (Press enter to. TexturePacker simply cropped my sprites too tightly for the shader effects to show. First convert the image into sprite in unity editor, then you can load that at. TexturePacker has 2 crop modes in Unity - to remove transparency around the sprites which consumes memory and GPU. In the center you can see how TexturePacker arranges all the sprites in a optimized way, representing your. If we have a 140x140 sprite, it will automatically be altered to match the hardware constraints. this function get the desired heigth, according to the width specified and the size of the texture of the sprite on the image. Upon further research, I think the cause of the issue isn’t a particular conflict between TexturePacker and Unity. Worst case would be a hardware that can only process square sprites with width and height matching a power of 2 (128x128,256x256.). 4)Try to add something new to the sprite sheet in TexturePacker. Using reflection to invoke this function it seems to return the original size of the texture (as opposed to the imported size).I got the solution, remember that this works with "preserve aspect" allowed on the Image component. Heres what happens: 1)Create a sprite sheet of a character in TexturePacker and export it to Unity 2)Great, Anima2D detects each sprite/texture and you can create a SpriteMesh 3)Cool now we can create the bones, do the animations, etc.

This worked but was very slow due to the need to reimport the texture asset twice.Īfter chatting with some developers in the IRC channel we discovered the internal function "TextureImporter.GetWidthAndHeight". Having searched the web thoroughly the best solution that I could come across was to temporarily alter the texture importer settings for a texture asset, and then restore them. the character above is a 32x32 sprite For a size reference, the character above is a 32x32 sprite. It is often useful to access the original width and height of the texture asset from editor scripts when performing certain calculations, especially when working with things like atlases. Whenever Unity makes a new sprite, it uses a texture.

So if you have a texture that measures 210x210 in Photoshop, when imported into Unity the texture will likely read 256x256 due to NPOT and/or maximum resolution.

Unity does not provide a documented API for accessing the width and height of a texture asset before any processing has been applied by the texture importer.
