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

PhysicsShapeGroup2D.SetShapeAdjacentVertices

Declaration

public void SetShapeAdjacentVertices(int shapeIndex, bool useAdjacentStart, bool useAdjacentEnd, Vector2 adjacentStart, Vector2 adjacentEnd);

Параметры

Параметр Описание
shapeIndex Индекс формы, которая должна быть изменена, который хранится в PhysicsShapeGroup2D.
useAdjacentStart Устанавливает свойство PhysicsShape2D.useAdjacentStart выбранной формы.
useAdjacentEnd Устанавливает свойство PhysicsShape2D.useAdjacentEnd выбранной формы.
adjacentStart Устанавливает свойство PhysicsShape2D.adjacentStart выбранной формы.
adjacentEnd Устанавливает свойство PhysicsShape2D.adjacentEnd выбранной формы.

Описание

Задает смежные вершины фигуры.

NOTE: Вызов этого на PhysicsShape2D, который не имеет shapeType или PhysicsShapeType2D.Edges приведет к возникновению исключения.

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Assertions;

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

// Add a list of Edges. var shapeIndex = shapeGroup.AddEdges ( vertices: new List<Vector2> { new Vector2(-4f, 0f), new Vector2(-2f, -0.5f), new Vector2(0f, 0f), new Vector2(2f, -0.5f), new Vector2(4f, 0f), },

edgeRadius: 0.5f,

useAdjacentStart: true, useAdjacentEnd: true, adjacentStart: new Vector2(-5f, -1f), adjacentEnd: new Vector2(6f, 2f) );

// Fetch the actual shape created. var physicsShape = shapeGroup.GetShape(shapeIndex);

// Validate what we created. Assert.AreEqual(PhysicsShapeType2D.Edges, physicsShape.shapeType); Assert.AreApproximatelyEqual(0.5f, physicsShape.radius); Assert.AreEqual(5, physicsShape.vertexCount); Assert.IsTrue(physicsShape.useAdjacentStart); Assert.IsTrue(physicsShape.useAdjacentEnd); Assert.AreEqual(new Vector2(-5f, -1f), physicsShape.adjacentStart); Assert.AreEqual(new Vector2(6f, 2f), physicsShape.adjacentEnd);

// Set the adjacent vertices. shapeGroup.SetShapeAdjacentVertices( shapeIndex, useAdjacentStart: true, useAdjacentEnd: true, adjacentStart: new Vector2(-10f, -5f), adjacentEnd: new Vector2(12f, 3f));

// Fetch the updated shape. physicsShape = shapeGroup.GetShape(shapeIndex);

// Validate what we updated. Assert.IsTrue(physicsShape.useAdjacentStart); Assert.IsTrue(physicsShape.useAdjacentEnd); Assert.AreEqual(new Vector2(-10f, -5f), physicsShape.adjacentStart); Assert.AreEqual(new Vector2(12f, 3f), physicsShape.adjacentEnd); } }