Version: 2018.3 (switch to 2019.1)
LanguageEnglish
  • C#

AssetPostprocessor.OnPostprocessCubemap(Cubemap)

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Add this function to a subclass to get a notification just before a cubemap texture has completed importing.

If the cubemap texture is modified, it needs to be readable, as shown in the example below. Set the isReadable flag to True in the Importer settings of the Editor (Read/Write Enabled). If the cubemap texture does not have to be readable at runtime, use texture.Apply(true, true) to update the mipmaps and make the cubemap texture unreadable at runtime.

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. } } }

Did you find this page useful? Please give it a rating: