shapeIndex | 存储在 PhysicsShapeGroup2D 中的形状的索引。形状索引从零开始,形状组的形状数量由 shapeCount 指定。 |
vertices | 一个列表,它将填充 PhysicsShapeGroup2D 中所有形状顶点的副本。 |
获取 PhysicsShapeGroup2D 中形状顶点的副本。
注意:因为这是一个副本,所以之后更改指定的形状 vertices
列表不会更改 PhysicsShapeGroup2D。
using System.Collections.Generic; 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 shapeIndex = shapeGroup.AddCapsule ( vertex0: Vector2.down, vertex1: Vector2.up, radius: 0.5f );
// Fetch the shape vertices from the shape group. var vertices = new List<Vector2>(); shapeGroup.GetShapeVertices(shapeIndex, vertices);
// validate the Capsule vertices (2). Assert.AreEqual(Vector2.down, vertices[0]); Assert.AreEqual(Vector2.up, vertices[1]); } }