private void SourceTilemap_EventTilemapChanged(object sender, TilemapChangedEventArgs e) { // If we resized our tilemap, we'll have to do a full update Point2 newTileCount = GetTileCount(this.sourceTilemaps); if (newTileCount != this.tileCount) { this.UpdateRigidBody(false); } // Otherwise, only update the sectors that are affected by the change else { Point2 minSector = new Point2( MathF.Clamp(e.Pos.X / SectorSize, 0, this.sectorCount.X), MathF.Clamp(e.Pos.Y / SectorSize, 0, this.sectorCount.Y)); Point2 maxSector = new Point2( MathF.Clamp(1 + (e.Pos.X + e.Size.X) / SectorSize, 0, this.sectorCount.X), MathF.Clamp(1 + (e.Pos.Y + e.Size.Y) / SectorSize, 0, this.sectorCount.Y)); RigidBody body = this.GameObj.GetComponent <RigidBody>(); this.UpdateRigidBody(body, minSector.X, minSector.Y, maxSector.X - minSector.X, maxSector.Y - minSector.Y); } }
private void SourceTilemap_EventTilemapChanged(object sender, TilemapChangedEventArgs e) { // If we resized our tilemap, we'll have to do a full update Point2 newTileCount = GetTileCount(this.sourceTilemaps); if (newTileCount != this.tileCount) { this.UpdateRigidBody(false); } // Otherwise, only update the sectors that are affected by the change else { Point2 minSector = new Point2( MathF.Clamp(e.Pos.X / SectorSize, 0, this.sectorCount.X), MathF.Clamp(e.Pos.Y / SectorSize, 0, this.sectorCount.Y)); Point2 maxSector = new Point2( MathF.Clamp(1 + (e.Pos.X + e.Size.X) / SectorSize, 0, this.sectorCount.X), MathF.Clamp(1 + (e.Pos.Y + e.Size.Y) / SectorSize, 0, this.sectorCount.Y)); RigidBody body = this.GameObj.GetComponent<RigidBody>(); this.UpdateRigidBody(body, minSector.X, minSector.Y, maxSector.X - minSector.X, maxSector.Y - minSector.Y); } }