分配给碰撞器的自定义 PhysicsShape2D 的总数。(只读)
此处表示的所有形状都包含 customVertexCount 的总顶点数量。
注意: 此属性不应与 Collider2D.shapeCount 混淆,后者是 Collider2D 上活动形状的数量。 CustomCollider2D 也具有此属性。如果 Collider2D 被禁用、不活动或处于 错误 状态,则 Collider2D.shapeCount 将为零,而 customShapeCount 将始终是分配的自定义 PhysicsShape2D 的数量。
using UnityEngine; using UnityEngine.Assertions;
public class Example : MonoBehaviour { void Start() { // Fetch the custom collider. var customCollider = GetComponent<CustomCollider2D>();
// Create a shape group. var shapeGroup = new PhysicsShapeGroup2D();
// Add a Circle to the shape group. shapeGroup.AddCircle ( center: new Vector2(-1f, 0f), radius: 0.5f );
// Add a box to the shape group. shapeGroup.AddBox ( center: new Vector2(1f, 0f), size: new Vector2(1f, 1f) );
// Assign our shapes. customCollider.SetCustomShapes(shapeGroup);
// Validate the custom shape count. Assert.AreApproximatelyEqual(shapeGroup.shapeCount, customCollider.customShapeCount); } }