AssetPostprocessor.OnPostprocessTexture(Texture2DArray)
Описание
Добавьте эту функцию в подкласс, чтобы получать уведомление, когда texture2DArray завершает импорт перед сжатием Unity.
Вы не можете выбрать формат сжатия на данном этапе. Если вы хотите изменить формат сжатия на основе имени файла или других атрибутов текстуры, используйте AssetPostprocessor.OnPreprocessTexture.
Однако, если вы измените настройки TextureImporter таким образом, это не повлияет на текстуру, которую Unity импортирует в данный момент, но будет применено при следующем импорте Unity этой текстуры. Это приводит к непредсказуемым результатам.
using UnityEditor; using UnityEngine; using System.Collections;
// Postprocesses all 2D texture arrays that are placed in a folder // "invert color" to have their colors inverted. public class InvertColor : AssetPostprocessor { // Increment the version number, when the AssetPostprocessors code/behavior is changed static readonly uint k_Version = 0; public override uint GetVersion() { return k_Version; }
void OnPostprocessTexture2DArray(Texture2DArray texture) { // Only post process textures if they are in a folder // "invert color" or a sub folder of it. string lowerCaseAssetPath = assetPath.ToLower(); if (lowerCaseAssetPath.IndexOf("/invert color/") == -1) return;
for (int slice = 0; slice < texture.depth; ++slice) { for (int m = 0; m < texture.mipmapCount; m++) { Color[] c = texture.GetPixels(m);
for (int i = 0; i < c.Length; i++) { c[i].r = 1 - c[i].r; c[i].g = 1 - c[i].g; c[i].b = 1 - c[i].b; } texture.SetPixels(c, slice, m); } }
// Instead of setting pixels for each mipmap level, you can modify // the pixels in the highest mipmap then use texture.Apply(true); // to generate lower mip levels. } }