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
↧