Version: 2023.2

CompositeCollider2D

class in UnityEngine

/

继承自:Collider2D

切换到手册

描述

可合并其他碰撞体的碰撞体。

A CompositeCollider2D merges other Colliders together when their Collider2D.compositeOperation is anything other than Collider2D.CompositeOperation.None, that is, whenever a composite operation is selected.

When a Composite Collider uses a Collider, the Editor will ignore and not show the Collider2D.sharedMaterial, Collider2D.isTrigger & Collider2D.compositeOperation properties. The same properties on the CompositeCollider2D will be used instead. You should set these properties on the Composite Collider to merge all Colliders into the Composite Collider.

变量

edgeRadius控制该碰撞体创建的所有边缘的半径。
generationType指定生成复合碰撞体几何体的时间。
geometryType指定复合碰撞体应生成的几何体的类型。
offsetDistance在合成物理性状时,顶点偏移这个距离。在此距离内性状之间的所有顶点都会组合起来。
pathCount碰撞体中的路径数量。
pointCount获取碰撞体所有路径中的总点数。
useDelaunayMeshWhen the value is true, the Collider uses an additional Delaunay triangulation step to produce the Collider mesh. When the value is false, this additional step does not occur.
vertexDistance控制生成的顶点之间允许的最小距离。

公共函数

GenerateGeometry重新生成复合碰撞体几何体。
GetCompositedCollidersWhen any Collider2D is using any composite operation other than Collider2D.CompositeOperation.None then it is used by this CompositeCollider2D.
GetPath根据碰撞体的索引获取其路径。
GetPathPointCount根据碰撞体的索引获取指定的碰撞体路径中的点数。

继承的成员

变量

enabled启用的 Behaviour 可更新,禁用的 Behaviour 不可更新。
isActiveAndEnabledReports whether a GameObject and its associated Behaviour is active and enabled.
attachedRigidbody附加到 Collider2D 的 Rigidbody2D。
bounciness获取碰撞体使用的弹力。
bounds碰撞体的世界空间包围区域。
callbackLayersThe Layers that this Collider2D will report collision or trigger callbacks for during a contact with another Collider2D.
composite获取可附加到该碰撞体的 CompositeCollider2D。
compositeCapableIndicates if this Collider2D is capable of being composited by the CompositeCollider2D.
compositeOperationThe composite operation to be used by a CompositeCollider2D.
compositeOrderThe composite operation order to be used when a CompositeCollider2D is used.
contactCaptureLayersThe layers of other Collider2D involved in contacts with this Collider2D that will be captured.
density碰撞体的密度,用于计算其质量(如果启用自动质量)。
errorStateThe error state that indicates the state of the physics shapes the 2D Collider tried to create. (Read Only)
excludeLayersThe additional Layers that this Collider2D should exclude when deciding if a contact with another Collider2D should happen or not.
forceReceiveLayersThe Layers that this Collider2D can receive forces from during a Collision contact with another Collider2D.
forceSendLayersThe Layers that this Collider2D is allowed to send forces to during a Collision contact with another Collider2D.
friction获取碰撞体使用的摩擦力。
includeLayersThe additional Layers that this Collider2D should include when deciding if a contact with another Collider2D should happen or not.
isTrigger是否将碰撞体配置成了触发器?
layerOverridePriorityA decision priority assigned to this Collider2D used when there is a conflicting decision on whether a contact between itself and another Collision2D should happen or not.
localToWorldMatrixThe transformation matrix used to transform the Collider physics shapes to world space.
offset碰撞体几何形状的局部偏移。
shapeCountThe number of active PhysicsShape2D the Collider2D is currently using.
sharedMaterial应用于碰撞体的 PhysicsMaterial2D。
usedByEffector附加的特效器是否使用该碰撞体。
gameObject此组件附加到的游戏对象。始终将组件附加到游戏对象。
tag此游戏对象的标签。
transform附加到此 GameObject 的 Transform。
hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

Cast将碰撞体形状投射到从该碰撞体位置开始的场景中,而忽略该碰撞体本身。
ClosestPoint返回此碰撞体周边上最接近指定 position 的点。
CreateMesh创建与 Collider2D 几何体定义的区域相同的平面 Mesh。
Distance计算该碰撞体与另一个碰撞体的最小间距。
GetContacts获取此碰撞体的所有接触点。
GetShapeBoundsRetrieves a list of Bounds for all PhysicsShape2D created by this Collider2D, and returns the combined Bounds of the retrieved list.
GetShapeHash根据 Collider2D 的几何体生成简单哈希值。
GetShapesGets all the PhysicsShape2D used by the Collider2D.
IsTouching检查该碰撞体是否正在接触 /collider/。
IsTouchingLayers检查该碰撞体是否正在接触指定 layerMask 上的任何碰撞体。
Overlap获取与该碰撞体重叠的所有碰撞体的列表。
OverlapPoint检查碰撞体是否与空间中的某个点重叠。
Raycast将光线投射到从碰撞体位置开始的场景中,并忽略碰撞体本身。
BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentGets a reference to a component of type T on the same GameObject as the component specified.
GetComponentInChildrenGets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject.
GetComponentInParentGets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the same GameObject as the component specified.
GetComponentsInChildrenGets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject.
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。

消息

OnCollisionEnter2D当传入碰撞体与该对象的碰撞体接触时发送(仅限 2D 物理)。
OnCollisionExit2D当另一个对象上的碰撞体停止接触该对象的碰撞体时发送(仅限 2D 物理)。
OnCollisionStay2D在另一个对象上的碰撞体正在接触该对象的碰撞体时发送每个帧(仅限 2D 物理)。
OnTriggerEnter2D当另一个对象进入附加到该对象的触发碰撞体时发送(仅限 2D 物理)。
OnTriggerExit2D当另一个对象离开附加到该对象的触发碰撞体时发送(仅限 2D 物理)。
OnTriggerStay2D在另一个对象位于附加到该对象的触发碰撞体之内时发送每个帧(仅限 2D 物理)。