Version: 2023.2

Mesh.vertexAttributeCount

切换到手册
public int vertexAttributeCount ;

描述

返回网格所具有的顶点属性数。(只读)

此属性返回活动顶点属性数(请参阅 VertexAttributeDescriptor)。它可以与 GetVertexAttribute 一起用于查询有关网格中存在的顶点属性的信息, 而无需任何托管分配。

using UnityEngine;
using UnityEngine.Rendering;

public class ExampleScript : MonoBehaviour { void Start() { // Create a Mesh with custom vertex data layout var mesh = new Mesh(); mesh.SetVertexBufferParams(10, new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3), new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float32, 3), new VertexAttributeDescriptor(VertexAttribute.Color, VertexAttributeFormat.UNorm8, 4));

// Prints 3 (three attributes) Debug.Log($"Vertex stream count: {mesh.vertexAttributeCount}");

// Cleanup Object.DestroyImmediate(mesh); } }