// The following example combines a circle and a capsule shape. Attach this// script to a GameObject, then enter Play mode to check the combined shape.using UnityEngine;using Unity.U2D.Physics;using Unity.Collections;public class CombineShapes : MonoBehaviour{ // Create the definition for a circle object. public CircleGeometry circleGeometry = CircleGeometry.defaultGeometry; public PhysicsTransform circleTransform = new Vector2(0f, 0f); // Create the definition for a capsule object. public CapsuleGeometry capsuleGeometry = CapsuleGeometry.defaultGeometry; public PhysicsTransform capsuleTransform = new Vector2(0.75f, 0f); private void Awake() { PhysicsWorld world = PhysicsWorld.defaultWorld; // Create a composer to combine shapes. PhysicsComposer composer = PhysicsComposer.Create(Allocator.Temp); // Add both shapes to the composer. composer.AddLayer(circleGeometry, circleTransform); composer.AddLayer(capsuleGeometry, capsuleTransform, PhysicsComposer.Operation.OR); // Combine the shapes. using NativeArray<PolygonGeometry> combinedShape = composer.CreatePolygonGeometry(new Vector2(1f, 1f), Allocator.Temp); // Create a body with the combined shapes. PhysicsBody body = world.CreateBody(); using NativeArray<PhysicsShape> shapes = body.CreateShapeBatch(combinedShape, PhysicsShapeDefinition.defaultDefinition); // Destroy the composer to also destroy the temporary allocator. composer.Destroy(); }}
Get the number of geometries that were rejected during the last Geometry Composition. Geometry can be rejected for a number of reasons such as vertices being collinear or too close etc. Whilst "pure" geometry is always valid, this geometry is meant to be used by physics which has constraints on what it can accept. All geometry successfully created will always be valid when used by physics. If you notice thin/small gaps in the composition, this is likely to be rejected geometry. Checking this property will help determine that.
Get/Set if Delaunay tessellation is to be used. Delaunay tessellation is enabled by default and produces far superior results. When Delaunay tessellation is disabled, curved areas can produce invalid geometry which is rejected therefore increase the _rejectedGeometryCount.
Create ChainGeometry from the composition by iterating all the layers added to the composition in the layer order specified, applying each operation specified. A limit is imposed on small vertex distances so be aware that this overload uses a vertex scale of _one so consider using the overload which allows you to increase this if required.
Create PolygonGeometry.ConvexHull from the composition by iterating all the layers added to the composition in the layer order specified, applying each operation specified. A default vertex scale of _one is used here.
Create PolygonGeometry from the composition by iterating all the layers added to the composition in the layer order specified, applying each operation specified. A limit is imposed on small vertex distances so be aware that this overload uses a vertex scale of _one so consider using the overload which allows you to increase this if required.
Get the geometry islands from a previous polygon geometry composition i.e. a call to PhysicsComposer.CreatePolygonGeometry or PhysicsComposer.CreateConvexHulls. Each generated polygon or convex-hull belongs to a unique island defining a set of polygons that are connected together as they share edges. The array returned contains a series of ranges where each range is a unique connected island where the range indicates both the start index and length of the original polygon indices. The number of discovered unique islands is defined by the size of the returned array.
Creates multiple PolygonGeometry from the specified geometry. A limit is imposed on small vertex distances so it is recommended that the geometry is scaled appropriately rather than on the returned geometry so geometry is not discarded due to it being invalid.