unity3d

Importers and (Post)Processors

Syntax#

  • AssetPostprocessor.OnPreprocessTexture()

Remarks#

Use String.Contains() to process only assets that have a given string in their asset paths.

if (assetPath.Contains("ProcessThisFolder"))
{
    // Process asset
}

Texture postprocessor

Create TexturePostProcessor.cs file anywhere in Assets folder:

using UnityEngine;
using UnityEditor;

public class TexturePostProcessor : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter importer = assetImporter as TextureImporter;
        importer.anisoLevel = 1;
        importer.filterMode = FilterMode.Bilinear;
        importer.mipmapEnabled = true;
        importer.npotScale = TextureImporterNPOTScale.ToLarger;
        importer.textureType = TextureImporterType.Advanced;
    }
}

Now, every time Unity imports a texture it will have the following parameters: enter image description here

If you use postprocessor, you can not change texture parameters by manipulating Import Settings in editor.

When you hit Apply button the texture will be reimported and postprocessor code will run again.

A Basic Importer


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow