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

PhysicsShapeGroup2D.vertexCount

建议修改

成功!

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

关闭

提交失败

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

关闭

取消

public int vertexCount;

描述

形状组中用于表示所有PhysicsShape2D 的顶点总数。(只读)

using UnityEngine;
using UnityEngine.Assertions;

public class Example : MonoBehaviour { private const int ShapeCount = 10;

void Start() { // Create a shape group. // NOTE: We can hint to the shape group the capacity for shapes so that it's quicker when adding them. var shapeGroup = new PhysicsShapeGroup2D(shapeCapacity: ShapeCount);

// Add Boxes to the shape group. for (var n = 0; n < ShapeCount; ++n) { shapeGroup.AddBox ( center: new Vector2(n, 0f), size: new Vector2(0.25f, 0.25f) ); }

// Validate that we created the specified number of shapes. Assert.AreEqual(ShapeCount, shapeGroup.shapeCount);

// Validate that we created the correct number of vertices. // NOTE: Each Box has 4 vertices so we multiply this constant by the number of shapes. Assert.AreEqual(ShapeCount * 4, shapeGroup.vertexCount);

// Validate each shape. for (var n = 0; n < ShapeCount; ++n) { // Fetch the actual shape created. var physicsShape = shapeGroup.GetShape(n);

// Validate the shape. Assert.AreEqual(PhysicsShapeType2D.Polygon, physicsShape.shapeType); Assert.AreEqual(4, physicsShape.vertexCount); } } }