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

PhysicsShapeGroup2D.DeleteShape

建议更改

成功!

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

关闭

提交失败

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

关闭

取消

声明

public void DeleteShape(int shapeIndex);

参数

shapeIndex 存储在 PhysicsShapeGroup2D 中的形状的索引。

描述

销毁指定 shapeIndex 处的形状时,所有位于指定 shapeIndex 上方的其他形状的形状索引都将相应更新。

using UnityEngine;
using UnityEngine.Assertions;

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

// Add two Circles to the shape group. shapeGroup.AddCircle ( center: Vector2.left, radius: 1f ); var shapeIndex = shapeGroup.AddCircle ( center: Vector2.right, radius: 1f );

// Add a Box to the shape group. shapeGroup.AddBox ( center: new Vector2(3f, 2f), size: new Vector2(1f, 1f) );

// Validate the contents. Assert.AreEqual(1 + 1 + 1, shapeGroup.shapeCount); Assert.AreEqual(1 + 1 + 4, shapeGroup.vertexCount); Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(0).shapeType); Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(1).shapeType); Assert.AreEqual(PhysicsShapeType2D.Polygon, shapeGroup.GetShape(2).shapeType);

// Delete the second Circle shape. shapeGroup.DeleteShape(shapeIndex);

// Validate the contents. Assert.AreEqual(1 + 1, shapeGroup.shapeCount); Assert.AreEqual(1 + 4, shapeGroup.vertexCount); Assert.AreEqual(PhysicsShapeType2D.Circle, shapeGroup.GetShape(0).shapeType); Assert.AreEqual(PhysicsShapeType2D.Polygon, shapeGroup.GetShape(1).shapeType); } }