Search Unity

how to make OnPreProcesstexture ignore manually changed textures

Discussion in 'Scripting' started by techmage, Feb 21, 2012.

  1. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
    So I have this script here:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. public class TextureProcessor : AssetPostprocessor
    6. {  
    7.   void OnPreprocessTexture()
    8.     {
    9.        
    10.         TextureImporter importer = assetImporter as TextureImporter;
    11.         importer.anisoLevel = 0;
    12.         importer.filterMode = FilterMode.Bilinear;
    13.         importer.wrapMode = TextureWrapMode.Clamp;
    14.         importer.mipmapEnabled = false;
    15.         importer.textureFormat = TextureImporterFormat.PVRTC_RGB4;
    16.         importer.npotScale = TextureImporterNPOTScale.None;
    17.         importer.textureType = TextureImporterType.Advanced;
    18.         importer.maxTextureSize = 2048;
    19.    
    20.        
    21.     }  
    22. }
    23.  
    It changes the default settings on every texture that Unity imports, and it works just fine.

    But the thing is it disallows me to manually edit a textures settings. If I go into a texture's settings, and change something, then click apply, it will do it's thing, but then this script will override any manual edits I made in the settings.

    How do I change that? How can I make it so this script is always enabled, and it will also allow me to make manual changes to textures?
     
  2. techmage

    techmage

    Joined:
    Oct 31, 2009
    Posts:
    2,133
  3. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    you must enhance your importer to work basing on a naming scheme and only apply it to 'automatic textures'

    you can't change it anymore with what you set here as any texture when its imported (which happens when you click apply on the texture import settings) gets pushed through this right now, not just 'automatic handled textures'
     
  4. Noob_Vulcan

    Noob_Vulcan

    Joined:
    Mar 20, 2014
    Posts:
    14
    OnPreprocessTexture saves a lot of time . We all know how much time we spend in compressing a texture or loading it.
    Code (CSharp):
    1. public class MyTextureFormat : AssetPostprocessor
    2. {
    3.       void OnPreprocessTexture(){
    4.         TextureImporter texImport = assetImporter as TextureImporter;
    5.         texImport.textureType = TextureImporterType.Image;
    6.         texImport.alphaIsTransparency = true;
    7.         texImport.maxTextureSize = 512;
    8.         texImport.textureFormat = TextureImporterFormat.AutomaticTruecolor;
    9.       }
    10. }
     
    Last edited by a moderator: Feb 27, 2020