Advertisement
DirePixel

Texture Post Processor

Mar 25th, 2021 (edited)
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. namespace ManaSeed.Editor
  5. {
  6.     public class TexturePostProcessor : AssetPostprocessor
  7.     {
  8.         private void OnPostprocessTexture(Texture2D texture)
  9.         {
  10.             TextureImporter importer = assetImporter as TextureImporter;
  11.             importer.spritePixelsPerUnit = 16;
  12.             importer.wrapMode = TextureWrapMode.Clamp;
  13.             importer.filterMode = FilterMode.Point;
  14.             importer.textureCompression = TextureImporterCompression.Uncompressed;
  15.  
  16.             if (texture.width <= 32 && texture.height <= 32)
  17.                 importer.maxTextureSize = 32;
  18.             else if (texture.width <= 64 && texture.height <= 64)
  19.                 importer.maxTextureSize = 64;
  20.             else if (texture.width <= 128 && texture.height <= 128)
  21.                 importer.maxTextureSize = 128;
  22.             else if (texture.width <= 256 && texture.height <= 256)
  23.                 importer.maxTextureSize = 256;
  24.             else if (texture.width <= 512 && texture.height <= 512)
  25.                 importer.maxTextureSize = 512;
  26.             else if (texture.width <= 1024 && texture.height <= 1024)
  27.                 importer.maxTextureSize = 1024;
  28.             else if (texture.width <= 2048 && texture.height <= 2048)
  29.                 importer.maxTextureSize = 2048;
  30.             else if (texture.width <= 4096 && texture.height <= 4096)
  31.                 importer.maxTextureSize = 4096;
  32.             else if (texture.height <= 8192 && texture.height <= 8192)
  33.                 importer.maxTextureSize = 8192;
  34.             else
  35.                 importer.maxTextureSize = 16384;
  36.  
  37.             Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D));
  38.             if (asset)
  39.             {
  40.                 EditorUtility.SetDirty(asset);
  41.             }
  42.             else
  43.             {
  44.                 texture.anisoLevel = 0;
  45.                 texture.filterMode = FilterMode.Point;
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement