当前位置: 首页>>代码示例>>C#>>正文


C# RigidBody.AddShape方法代码示例

本文整理汇总了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;
        }
开发者ID:SirePi,项目名称:duality,代码行数:61,代码来源:TilemapCollider.cs


注:本文中的Duality.Components.Physics.RigidBody.AddShape方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。