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

PhysicsShapeGroup2D.shapeCount

建议更改

成功!

感谢您帮助我们提升 Unity 文档的质量。尽管我们无法接受所有提交的内容,但我们会阅读用户提供的每一项建议更改,并视情况进行更新。

关闭

提交失败

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

关闭

取消

公开 int shapeCount;

说明

形状组中 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); } } }