版本: Unity 6 (6000.0)
语言英语
  • C#

PhysicsShape2D.vertexStartIndex

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交的内容,但我们确实会阅读用户提供的每个建议的更改,并在适用时进行更新。

关闭

提交失败

由于某些原因,您的建议更改无法提交。请<a>重试</a>几分钟后。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

public int vertexStartIndex;

描述

此形状的几何图形在 PhysicsShapeGroup2D 中的起始索引。

PhysicsShapeGroup2D 中,多个 PhysicsShape2D 被表示为单个顶点列表。此索引是该形状在该列表中的起点。

其他资源:GetShapeVertexGetShapeVertices

using UnityEngine;
using UnityEngine.Assertions;

public class Example : MonoBehaviour { void Start() { // Create a shape group. var shapeGroup = new PhysicsShapeGroup2D();

// Add a Capsule to the shape group. var capsuleShapeIndex = shapeGroup.AddCapsule ( vertex0: Vector2.down, vertex1: Vector2.up, radius: 0.5f );

// Add a Circle to the shape group. var circleShapeIndex = shapeGroup.AddCircle ( center: new Vector2(-2f, 3f), radius: 1f );

// Fetch the shapes. var capsuleShape = shapeGroup.GetShape(capsuleShapeIndex); var circleShape = shapeGroup.GetShape(circleShapeIndex);

// Validate the shape vertex count. Assert.AreEqual(2, capsuleShape.vertexCount); Assert.AreEqual(1, circleShape.vertexCount);

// Validate the Capsule vertex start index. // NOTE: The Capsule is the first shape so its index is 0. // It has 2 vertices at indices 0 and 1. Assert.AreEqual(0, capsuleShape.vertexStartIndex);

// Validate the Circle vertex start index. // NOTE: The Circle is the second shape so its index is 0. // It comes after the Capsule which has 2 vertices at indices 0 and 1 so // the Circle start index is 2. Assert.AreEqual(2, circleShape.vertexStartIndex); } }