Version: 2022.3
言語: 日本語
public int shapeCount ;

説明

The total number of PhysicsShape2D in the shape group. (Read Only)

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); } } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961