
本文将在Unity中介绍Texture2DArray和Texture3D使用导入设置创建。
Texture2DArray和Texture3D干什么的
Texture2DArray或Texture3D是包含相同大小和格式的纹理的资产。
- Texture2DArray:可以像数组一样进行索引。
- Texture3D:保存多个纹理作为3D信息。
使用脚本
到目前为止,这些资产只能使用脚本创建,例如,在Texture2DArray的情况下,它是按如下方式创建的。
using System.IO;
using UnityEditor;
using UnityEngine;
public class Texture2DArrayExample
{
[MenuItem("Example/Create Texture 2D Array")]
private static void CreateTexture2DArray()
{
const int width = 64;
const int height = 64;
const int depth = 10;
const TextureFormat format = TextureFormat.ARGB32;
var tex2dArr = new Texture2DArray(width, height, depth, format, false)
{
filterMode = FilterMode.Bilinear,
wrapMode = TextureWrapMode.Clamp
};
// Create a Texture2DArray while changing the color appropriately for each texture
for (var i = 0; i < depth; i++)
{
var color = Random.ColorHSV();
var pixels = new Color[width * height];
for (var j = 0; j < width * height; j++)
{
pixels[j] = color;
}
tex2dArr.SetPixels(pixels, i);
}
tex2dArr.Apply();
AssetDatabase.CreateAsset(tex2dArr, Path.Combine("Assets", "TestTexture2DArray.asset"));
}
}
从导入设置创建
从Unity2020.2开始,可以从纹理导入设置创建,可以通过从形状设置中选择2D阵列或3D并应用来设置它。
如下所示:

…
以上是3D天堂关于Texture2DArray和Texture3D使用导入设置创建的全部内容,如果你有任何反馈,请随时在本页面下方留言。