Version: 2023.1
言語: 日本語
public void SetPixels32 (Color32[] colors, int miplevel= 0);

パラメーター

colors The array of pixel colours to use. This is a 2D image flattened to a 1D array.
miplevel The mipmap level to write colors to. The range is 0 through the texture's Texture.mipmapCount. The default value is 0.

説明

Sets the pixel colors of an entire mipmap level.

This method sets pixel data for the texture in CPU memory. Texture.isReadable must be true, and you must call Apply after SetPixels32 to upload the changed pixels to the GPU.

colors must contain the pixels slice by slice starting at the front of the texture. Each slice must contain the pixels row by row, starting at the bottom left of the texture. The size of the array must be the width × height × depth of the mipmap level.

A single call to SetPixels32 is usually faster than multiple calls to SetPixel, especially for large textures.

SetPixels32 might be slower than some other texture methods because it converts the Color32 struct into the format the texture uses. To set pixel data more quickly, use SetPixelData instead.

You can use SetPixels32 with the following texture formats: Alpha8 ARGB32 ARGB4444 BGRA32 R16 R16_SIGNED R8 R8_SIGNED RFloat RG16 RG16_SIGNED RG32 RG32_SIGNED RGB24 RGB24_SIGNED RGB48 RGB48_SIGNED RGB565 RGB9e5Float RGBA32 RGBA32_SIGNED RGBA4444 RGBA64 RGBA64_SIGNED RGBAFloat RGBAHalf RGFloat RGHalf RHalf For all other formats, SetPixels32 fails. Unity throws an exception when SetPixels32 fails.

See Also: SetPixels, SetPixelData, GetPixels32, GetPixels, Apply, GetRawTextureData, LoadRawTextureData, mipmapCount.

using UnityEngine;

public class Example : MonoBehaviour { // This script tints a texture's mipmap levels with different colors.

void Start() { Renderer rend = GetComponent<Renderer>();

// Duplicate the original texture and assign to this GameObject's material. Texture2D texture = (Texture2D)Instantiate(rend.material.mainTexture); rend.material.mainTexture = texture;

// Create the colors to use var colors = new Color32[3]; colors[0] = Color.red; colors[1] = Color.green; colors[2] = Color.blue; var mipCount = Mathf.Min(3, texture.mipmapCount);

// For each mipmap level, use GetPixels to fetch an array of pixel data, and use SetPixels32 to fill the mipmap level with one color. for (var mip = 0; mip < mipCount; ++mip) { var cols = texture.GetPixels32(mip); for (var i = 0; i < cols.Length; ++i) { cols[i] = Color32.Lerp(cols[i], colors[mip], 0.33f); } texture.SetPixels32(cols, mip); }

// Copy the changes to the GPU, and don't recalculate mipmap levels. texture.Apply(false); } }

public void SetPixels32 (int x, int y, int blockWidth, int blockHeight, Color32[] colors, int miplevel= 0);

パラメーター

x The x coordinate to place the block of pixels at. The range is 0 through (texture width - 1).
y The y coordinate to place the block of pixels at. The range is 0 through (texture height - 1).
blockWidth The width of the block of pixels to set.
blockHeight The height of the block of pixels to set.
colors The array of pixel colours to use. This is a 2D image flattened to a 1D array. Must be blockWidth x blockHeight in length.
miplevel The mipmap level to write colors to. The range is 0 through the texture's Texture.mipmapCount. The default value is 0.

説明

Sets the pixel colors of part of a mipmap level.

This version of SetPixels32 sets part of a mipmap level instead of the whole mipmap level.

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