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 { 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 mip map levels, you can also // modify only the pixels in the highest mip level. And then simply use // texture.Apply(true); to generate lower mip levels. } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961