本文整理汇总了C#中Duality.Components.Physics.RigidBody.AddShape方法的典型用法代码示例。如果您正苦于以下问题:C# RigidBody.AddShape方法的具体用法?C# RigidBody.AddShape怎么用?C# RigidBody.AddShape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Duality.Components.Physics.RigidBody
的用法示例。
在下文中一共展示了RigidBody.AddShape方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateRigidBody
private void UpdateRigidBody(RigidBody body, int sectorX, int sectorY)
{
Sector sector = this.sectors[sectorX, sectorY];
// Determine collision checksum
this.tempCollisionData.Clear();
int newChecksum = this.MergeCollisionData(sectorX, sectorY, this.tempCollisionData);
// If it differs from our previous value, update collision shapes
if (sector.Checksum != newChecksum)
{
// Clean up old shapes
if (sector.Shapes != null)
{
foreach (ShapeInfo shape in sector.Shapes)
body.RemoveShape(shape);
sector.Shapes.Clear();
}
else
{
sector.Shapes = new List<ShapeInfo>();
}
// Generate new shapes
{
// Determine general working data
Tilemap tilemap = this.referenceTilemap;
Tileset tileset = tilemap != null ? tilemap.Tileset.Res : null;
Vector2 tileSize = tileset != null ? tileset.TileSize : Tileset.DefaultTileSize;
Point2 sectorBaseTile = new Point2(
sectorX * SectorSize,
sectorY * SectorSize);
Vector2 sectorBasePos = sectorBaseTile * tileSize;
// Clear the temporary edge map first
this.tempEdgeMap.Clear();
// Populate the edge map with fence and block geometry
AddFenceCollisionEdges(this.tempCollisionData, this.tempEdgeMap);
AddBlockCollisionEdges(this.tempCollisionData, this.tempEdgeMap, sectorBaseTile, this.tileCount);
if (this.solidOuterEdges)
AddBorderCollisionEdges(this.tempEdgeMap, sectorBaseTile, this.tileCount);
// Now traverse the edge map and gradually create chain / loop
// shapes until all edges have been used.
Rect localRect = Rect.Align(this.origin, 0, 0, this.tileCount.X * tileSize.X, this.tileCount.Y * tileSize.Y);
GenerateCollisionShapes(this.tempEdgeMap, localRect.TopLeft + sectorBasePos, tileSize, this.roundedCorners, sector.Shapes);
// Add all the generated shapes to the target body
foreach (ShapeInfo shape in sector.Shapes)
{
body.AddShape(shape);
shape.Friction = this.shapeFriction;
shape.Restitution = this.shapeRestitution;
}
}
sector.Checksum = newChecksum;
}
this.sectors[sectorX, sectorY] = sector;
}