How to set the Texture Mesh Type to"Full rect"in the editor script

I know how to change it in the inspector,
but have no idea how to mass chang the settings in my editor script.
The TextureImporter class seems have none relative attribute.

This might be helpful to someone: I have such a plenty of texture need to handle,so I write a third-party tool to batch opening the xxx.png.meta file,and modify the field "spriteMeshType" to 0,it's just a text file.

2 Answers

2

Hi. Much late, but it’s in TextureImporterSettings. This is how I do it to set FullRect with 0 extrude.

class SunImporter : AssetPostprocessor
{
    void OnPreprocessTexture()
    {
        if (assetPath.Contains("_Sun")
        {
            TextureImporter textureImporter = (TextureImporter)assetImporter;
            textureImporter.alphaSource = TextureImporterAlphaSource.None;
            textureImporter.sRGBTexture = false;
            textureImporter.spritePackingTag = "Suns";
            textureImporter.textureCompression = TextureImporterCompression.CompressedHQ;
            textureImporter.compressionQuality = 100;

            TextureImporterSettings textureSettings = new TextureImporterSettings();
            textureImporter.ReadTextureSettings(textureSettings);
            textureSettings.spriteMeshType = SpriteMeshType.FullRect;
			textureSettings.spriteExtrude = 0;
            textureImporter.SetTextureSettings(textureSettings);
        }
    }
}

this is only works in editor not build

As far as I know this is only part of the sprite creation process. I don’t know why it’s not in TextureImporter but here’s a workaround:

If your sprite is already created then you’ll have to create a new one and replace your old one using Sprite.Create. The enumeration is SpriteMeshType. One of the overloads will let you set the SpriteMeshType.

Thank you for the quick reply.Hmm...that is a soluation