Version: 2022.1

Cubemap.GetPixelData

切换到手册
public NativeArray<T> GetPixelData (int mipLevel, CubemapFace face);

参数

mipLevel The mip level to reference.
face The Cubemap face to reference.

返回

NativeArray<T> The 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 and Cubemap face. For example, for a 16x16 sized Texture of RGBA32 format, getting the mip=1 level (8x8 size) will result in a 256-byte array or a 64-element array if Color32 is used as a type.

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 mip map, 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, GetPixelData.

using UnityEngine;

public class ExampleScript : MonoBehaviour { public void Start() { var m_Cubemap = new Cubemap(16, TextureFormat.RGBA32, true); var mip0Face4 = m_Cubemap.GetPixelData<Color32>(1, CubemapFace.PositiveZ);

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

m_Cubemap.Apply(false); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961