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.
CloseFor 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.
ClosemipLevel | The mip level to reference. |
face | The Cubemap face to reference. |
element | The array slice to reference. |
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 Cubemap face and array element. 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 (this also applies to any array element).
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.
See Also: Apply, SetPixels, SetPixels32, GetPixelData.
using UnityEngine;
public class ExampleScript : MonoBehaviour { public void Start() { var m_CubemapArray = new CubemapArray(16, 3, TextureFormat.RGBA32, true); var mip0Face4element1 = m_CubemapArray.GetPixelData<Color32>(1, CubemapFace.PositiveZ, 1);
// pixels in mip = 1, CubemapFace.PositiveZ from the second array element are filled with white color for (int i = 0; i < mip0Face4element1.Length; i++) { mip0Face4element1[i] = new Color32(255, 255, 255, 255); }
m_CubemapArray.Apply(false); } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!