Unity 6.3
0 онлайн 2 гостей 3 в системе
Вход

AssetPostprocessor.OnPostprocessTexture(Texture2D)

Описание

Добавьте эту функцию в подкласс, чтобы получать уведомление, когда texture2D завершает импорт перед сжатием Unity.

Вы не можете выбрать формат сжатия на данном этапе. Если вы хотите изменить формат сжатия на основе имени файла или других атрибутов текстуры, используйте AssetPostprocessor.OnPreprocessTexture.

Однако, если вы измените настройки TextureImporter таким образом, это не повлияет на текстуру, которую Unity импортирует в данный момент, но будет применено при следующем импорте Unity этой текстуры. Это приводит к непредсказуемым результатам.

using UnityEditor;
using UnityEngine;
using System.Collections;

// Postprocesses all textures 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 OnPostprocessTexture(Texture2D 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 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, m); } // Instead of setting pixels for each mip map level, you can modify // the pixels in the highest mipmap then use texture.Apply(true); // to generate lower mip levels. } }