- Home /
Modify sprite geometry using AssetPostprocessor
Hello!
I'm trying to use OnPostprocessSprites to modify sprite geometry when a sprite texture is imported. I've tried multiple methods now including replacing the sprites in the array with modified sprites, and modifying the sprites in place, however none yield to any useful changes to the data. I am able to modify the sprite names however, so this suggests that mutating the sprite data is possible.
The following excerpt shows the methods I've tried:
using UnityEngine;
using UnityEditor;
class TexturePostprocessor : AssetPostprocessor
{
void OnPostprocessSprites(Texture2D texture, Sprite[] sprites)
{
TextureImporter textureImporter = (TextureImporter)assetImporter;
if (textureImporter.assetPath.Contains("Drawings"))
{
for (int i = 0; i < sprites.Length; ++i)
{
sprites[i].name = "foo"; // works
sprites[i].rect = new Rect(0f, 0f, 0f, 0f); // readonly - not permitted
sprites[i].rect.Set(0f, 0f, 0f, 0f); // no visible effect
sprites[i].vertices[0] = Vector2.zero; // no visible effect
Vector2[] verts = sprites[i].vertices;
sprites[i].OverrideGeometry(verts, sprites[i].triangles); // not permitted at import time
sprites[i] = Sprite.Create(texture, sprites[i].rect, Vector2.zero); // no visible effect
}
}
}
}
Has anyone got any thoughts on how modifying sprite geometry at import time could be achieved?
Your answer
Follow this Question
Related Questions
How can I change the default max size of a texture from an editor script (in import settings)? 1 Answer
Can you make an EditorWindow pop up and block the asset import process while it's open? 0 Answers
Sprite Based Score Rendering 1 Answer
confusion with sprites. 0 Answers
Slice sprites that aren't rectangular 0 Answers