How do you use code to set spriteAlignment for sub-images of a sprite in Multiple mode?
In a class derived from AssetPostprocessor, I use this code to change some default settings when importing image assets:
void OnPreprocessTexture (){
TextureImporter textureImporter = (TextureImporter)assetImporter;
//This successfully turns off filtering for my pixel art
textureImporter.filterMode = FilterMode.Point;
//This sets alignment to top left for regular sprites (Sprite Mode=Single),
//but not if Sprite Mode = Multiple.
TextureImporterSettings texSettings = new TextureImporterSettings();
textureImporter.ReadTextureSettings(texSettings);
texSettings.spriteAlignment = (int)SpriteAlignment.TopLeft;
textureImporter.SetTextureSettings(texSettings);
}
However, this doesn't work for the sub-images when the sprite mode is "Multiple". When I open the sprite editor, each sub-image seems to have its own alignment setting but I can't figure out how to access these with code.
Answer by dsoodak · Jun 30, 2017 at 06:20 PM
Figured it out: textureImporter.spritesheet[i].alignment= (int)SpriteAlignment.TopLeft;
Your answer
Follow this Question
Related Questions
Sprite didn't change more than once 0 Answers
How do I get the Box Collidor to form around the shape of the Sprite? 2 Answers
[2D] Updating PSB I had previously rigged and animated BREAKS entire rig 0 Answers
[SOLVED] Cannot change Texture Type, stuck on Editor GUI and Legacy GUI 0 Answers
some sprites sliced in Game view, How can I fix this? 0 Answers