AssetPostprocessor.OnPostprocessCubemap(Cubemap)
Описание
Добавьте эту функцию в подкласс, чтобы получить уведомление перед тем, как текстура кубического сопоставления завершит импорт.
Обратите внимание, что вам следует избегать изменения настроек TextureImporter таким образом, так как это не будет иметь никакого влияния на текстуру, которая в настоящее время импортируется, но будет применяться при следующем импорте текстуры. Это поведение не является детерминированным и поэтому нежелательно.
using UnityEditor; using UnityEngine; using System.Collections;
// Postprocesses all cubemaps that are placed in a folder // Here we just halve the texels values public class ProcessCubemap : 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 OnPostprocessCubemap(Cubemap texture) { string lowerCaseAssetPath = assetPath.ToLower(); if (lowerCaseAssetPath.IndexOf("/postprocessedcubemaps/") == -1) return;
for (int m = 0; m < texture.mipmapCount; m++) { for (int face = 0; face < 6; face++) { CubemapFace f = (CubemapFace)face; Color[] c = texture.GetPixels(f, m);
for (int i = 0; i < c.Length; i++) { c[i].r = c[i].r * 0.5f; c[i].g = c[i].g * 0.5f; c[i].b = c[i].b * 0.5f; }
texture.SetPixels(c, f, m); } // Instead of setting pixels for each mipmap level, you can also // modify only the pixels in the highest mip level. And then simply use // texture.Apply(true); to generate lower mip levels. } } }