Version: 2023.2
public PhysicsShape2D GetShape (int shapeIndex);

参数

shapeIndex The index of the shape stored the PhysicsShapeGroup2D. The shape index is zero-based with the shape group having a quantity of shapes specified by shapeCount.

返回

PhysicsShape2D Returns the shape stored at the specified shapeIndex.

描述

Gets the PhysicsShape2D stored at the specified shapeIndex.

NOTE: Because the PhysicsShape2D is a struct, this is a copy of the shape therefore changing the shape afterwards will not change the PhysicsShapeGroup2D.

using UnityEngine;
using UnityEngine.Assertions;

public class Example : MonoBehaviour { void Start() { // Create a shape group. var shapeGroup = new PhysicsShapeGroup2D();

// Add a Circle to the shape group. var circleShapeIndex = shapeGroup.AddCircle ( center: new Vector2(-2f, 3f), radius: 1f );

// Add a Capsule to the shape group. var capsuleShapeIndex = shapeGroup.AddCapsule ( vertex0: Vector2.down, vertex1: Vector2.up, radius: 0.5f );

// Validate the contents. Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(circleShapeIndex).shapeType); Assert.AreEqual(PhysicsShapeType2D.Capsule, shapeGroup.GetShape(capsuleShapeIndex).shapeType); } }