版本:Unity 6(6000.0)
语言中文(简体)
  • C#

PhysicsShapeGroup2D.SetShapeAdjacentVertices

建议更改

成功!

感谢您帮助我们提高 Unity 文档的质量。虽然我们无法接受所有提交内容,但我们会仔细阅读用户提出的每一条建议,并在适用情况下进行更新。

关闭

提交失败

您的建议更改由于某种原因未提交。请在数分钟后<a>重试</a>。感谢您抽出时间帮助我们提高 Unity 文档的质量。

关闭

取消

声明

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 属性。

说明

设置形状的相邻顶点。

注意:对 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); } }