Unity 6.3
0 онлайн 76 гостей 3 в системе
Вход

CustomCollider2D.ClearCustomShapes

Declaration

public void ClearCustomShapes();

Описание

Удаляет все фигуры и связанные вершины для этих фигур из Collider.

Любые существующие контакты для этого Collider будут пересчитаны на следующем этапе моделирования.

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 5 Circles to the shape group. shapeGroup.AddCircle(center: new Vector2(3f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(4f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(5f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(6f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(7f, 0f), radius: 0.5f);

// Assign our shapes. customCollider.SetCustomShapes(shapeGroup);

// Validate the contents of the custom collider. Assert.AreEqual(5, customCollider.customShapeCount);

// Clear all the remaining shapes. customCollider.ClearCustomShapes();

// Validate the contents of the custom collider. Assert.AreEqual(0, customCollider.customShapeCount); } }

Declaration

public void ClearCustomShapes(int shapeIndex, int shapeCount);

Параметры

Параметр Описание
shapeIndex Индекс формы, хранящейся в Collider.
shapeCount Число фигур, которые нужно удалить, начиная с указанного индекса.

Описание

Удаляет определенное количество фигур, определенных shapeCount, начиная с shapeIndex, вместе со всеми связанными вершинами, используемыми этими фигурами.

Любые существующие контакты для этого Collider будут пересчитаны на следующем этапе моделирования.

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 5 Circles to the shape group. shapeGroup.AddCircle(center: new Vector2(3f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(4f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(5f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(6f, 0f), radius: 0.5f); shapeGroup.AddCircle(center: new Vector2(7f, 0f), radius: 0.5f);

// Assign our shapes. customCollider.SetCustomShapes(shapeGroup);

// Validate the contents of the custom collider. Assert.AreEqual(5, customCollider.customShapeCount);

// Clear the first 2 shapes. customCollider.ClearCustomShapes(shapeIndex: 0, shapeCount: 2);

// Validate the contents of the custom collider. Assert.AreEqual(3, customCollider.customShapeCount);

// Clear the remaining 3 shapes. customCollider.ClearCustomShapes(shapeIndex: 0, shapeCount: 3);

// Validate the contents of the custom collider. Assert.AreEqual(0, customCollider.customShapeCount); } }