- Home /
As of now, sprite geometry doesn't seem to be editable, I'll use quads instead.
How to override geometry of a procedurally generated sprite in Editor Mode
HI,
I'm trying to develop a 2D tile tool custom editor window and I want it to be able to create non square sprites.
like this:
||
|| || (Imagine each set of two bars is a tile that after gets merged into a single sprite) ||||||
In editor mode I create several tiles from from sprites that I have in the assets folder and then merge them together into a single new texture by copying the pixels from the originals texture. Then I create a sprite using that texture. But when I want to use overrideSpriteGeometry:
"sprite.OverrideGeometry (verts, tris);"
I get this error:
"Not allowed to override geometry on sprite 'MySprite'".
I'm not creating assets files for the texture nor the sprite. The code in general would be like this:
Texture2D texture = new Texture2D(w,h);
texture.setPixels(pixelArray);
texture.apply();
Sprite Sprite = Sprite.Create (texture , rect, pivot, pixelsPerUnit);
sprite.overrideGeometry(vertices, triangles);
// Then add it to a GameObject
I have tried OnPostprocessSprites with a AssetPostprocessor subclass but it doesn't get called when creating a sprite like this.
¿How can I override the geometry of a sprite that was created this way?
Try this
TextureImporter footprintTextureImporter = (TextureImporter) AssetImporter.GetAtPath(footprintTextureName);
for (int s = 0; s < footprintTextureImporter.spritesheet.Length; ++s) {
footprintTextureImporter.spritesheet[s].rect.height = footprintTextureImporter.spritesheet[s].rect.height + 3;
}
footprintImporter.SaveAndReimport();