Quantcast
Channel: Questions in topic: "sprite editor"
Viewing all articles
Browse latest Browse all 190

The sprite size is still the original size after resize the texture in OnPostprocessTexture

$
0
0
Hi guys, In my project, I need to resize a sprite texture after it is imported. So I did this in AssetPostprocessor.OnPostprocessTexture(). But I noticed that the texture size was changed but the sprite size in Sprite Editor was still the original size. Like below screen shot shown: ![alt text][1] [1]: /storage/temp/33146-screenshot2.png I simplified my code as below to reproduce this problem easier. In the code, it will horizontally duplicate the original texture which means the width of imported texture is supposed to be twice as the original texture. It is in asset Inspector. But it isn't in Sprite Editor. using System.IO; using UnityEditor; using UnityEngine; public class CustomImporter : AssetPostprocessor { void OnPostprocessTexture(Texture2D texture) { TextureImporter importer = assetImporter as TextureImporter; importer.textureType = TextureImporterType.Sprite; Color[] pixels = texture.GetPixels(); int width = texture.width; int height = texture.height; texture.Resize(width * 2, height); texture.SetPixels(0, 0, width, height, pixels); texture.SetPixels(width, 0, width, height, pixels); } } Any body encountered same problem before? Any idea is welcome! Thanks, Cheng

Viewing all articles
Browse latest Browse all 190

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>