Version: 2021.2
언어: 한국어
public NativeArray<T> GetPixelData (int mipLevel);

파라미터

mipLevel The mip level to reference.

반환

NativeArray<T> View into the texture system memory data buffer.

설명

Gets raw data from a Texture for reading or writing.

This function returns a direct "view" into the Texture pixel data as a Unity.Collections.NativeArray.

A slice of the data will be returned according to the requested mip level. For example, for a 16x16x16 sized Texture of RGBA32 format, getting the mip=1 level (8x8x8 size) will result in a 2048-byte array or a 512-element array if Color32 is used as a type.

Note that not all platforms support compressed 3D Texture data so please consult SystemInfo.supportsCompressed3DTextures if you are using compressed formats.

You can read from and write to the returned array. If you write to it, you must call the Apply method to upload the Texture to the GPU. If an array returned by GetPixelData was used to fill up a non-0 level mipmap, then updateMipmaps must be set to false before calling the Apply method.

GetPixelData does not allocate memory; the returned NativeArray directly points to the Texture system memory data buffer.

It is recommended to immediately use or modify the data retrieved by this method and to not store the returned array for later use as the returned array can become invalid (i.e. it no longer points to valid memory) if the Texture is modified or updated after you called this method.

GetPixelData throws an exception when it fails.

See Also: Apply, SetPixels, SetPixels32, SetPixelData, SystemInfo.supportsCompressed3DTextures.

using UnityEngine;

public class ExampleScript : MonoBehaviour { public void Start() { var m_Texture3D = new Texture3D(16, 16, 16, TextureFormat.RGBA32, true); var mip0Data = m_Texture3D.GetPixelData<Color32>(1);

// pixels in mip = 1 are filled with white color for (int i = 0; i < mip0Data.Length; i++) { mip0Data[i] = new Color32(255, 255, 255, 255); }

m_Texture3D.Apply(false); } }