PhysicsShapeDefinition
A PhysicsShape definition used to specify important initial properties.
읽는 시간 3분최근 업데이트: 하루 전
Definition
- Type: Struct
- Namespace: Unity.U2D.Physics
- Assembly: UnityEngine.PhysicsCore2DModule
- Implements: IEquatable<PhysicsShapeDefinition>
public struct PhysicsShapeDefinition : IEquatable<PhysicsShapeDefinition>
Remarks
For more information about definitions, refer to PhysicsBodyDefinition.
Additional Resources: PhysicsBodyDefinition
Examples
// Create a shape definition, configure its density, then create a shape from it.using UnityEngine;using Unity.U2D.Physics;public class ShapeDefinitionExample : MonoBehaviour{ void Start() { PhysicsWorld world = PhysicsWorld.defaultWorld; PhysicsBody myBody = world.CreateBody(); PhysicsShapeDefinition shapeDefinition = new PhysicsShapeDefinition(); shapeDefinition.density = 5f; PhysicsShape shape = myBody.CreateShape(new CircleGeometry { radius = 1.5f }, shapeDefinition); }}
Fields
Value | Description |
|---|---|
| contactFilter | The contact filter used to control which contacts this shape can participate in. |
| moverData | The mover data used for the shape mover. |
| surfaceMaterial | The surface material for the shape comprising of many properties such as friction, bounciness, rolling resistance etc. |
Constructors
Constructor | Description |
|---|---|
| PhysicsShapeDefinition() | Create a default PhysicsShape definition. |
| PhysicsShapeDefinition(System.Boolean) | Create a default PhysicsShape definition. |
Properties
Property | Description |
|---|---|
| contactEvents | Controls whether this shape produces contact events which can be retrieved after the simulation has completed. This only applies to kinematic and dynamic bodies. A contact event is produced if either shapes involved have their contactEvents enabled. Changing this at run-time may lead to lost begin/end events. |
| contactFilterCallbacks | Controls whether this shape produces contact filter callbacks. A contact filter callback allows direct control over whether a contact will be created between a pair of shapes. This applies to both triggers and non-triggers but only with to Dynamic bodies These are relatively expensive so disabling them can provide a significant performance benefit. A contact filter callback will call the PhysicsShape.callbackTarget for both shapes involved if they implement PhysicsCallbacks.IContactFilterCallback. |
| density | The density, usually in kg/m^2, defaults to 1. This is not part of the surface material because this is for the interior of the shape, which may have other considerations, such as being hollow. |
| hitEvents | Controls whether this shape produces hit events which can be retrieved after the simulation has completed. This only applies to kinematic and dynamic bodies. This is ignored for triggers. |
| isTrigger | Whether the shape is a trigger, which generates overlap events but never generates a collision response. |
| preContactCallbacks | Controls whether this shape produces pre-contact and pre-continuous callbacks. This only applies to Dynamic bodies and is ignored for triggers. These are relatively expensive so disabling them can provide a significant performance benefit. |
| startMassUpdate | Should the body update its mass properties when this shape is created. Disabling this improves performance when multiple shapes are being added to the same body. The mass of a body can then be explicitly updated by calling PhysicsBody.ApplyMassFromShapes |
| startStaticContacts | Normally shapes on Static bodies don't create contacts when they are added to the world. This overrides that behavior and causes contact creation. This significantly slows down Static body creation which can be important when there are many Static shapes. This is implicitly always true for Triggers, Dynamic bodies and Kinematic bodies. |
| triggerEvents | Controls whether this shape produces trigger events which can be retrieved after the simulation has completed. |
| worldDrawing | Controls whether this shape is automatically drawn when the world is drawn. |
Static Properties
Property | Description |
|---|---|
| defaultDefinition | Get a default PhysicsShape definition. |