Box2DX.Dynamics.Controllers.Controller.RemoveBody C# (CSharp) Method

RemoveBody() public method

Removes a body from the controller list.
public RemoveBody ( Body body ) : void
body Body
return void
        public void RemoveBody(Body body)
        {
            //Assert that the controller is not empty
            Box2DXDebug.Assert(_bodyCount > 0);

            //Find the corresponding edge
            ControllerEdge edge = _bodyList;
            while (edge!=null && edge.body != body)
                edge = edge.nextBody;

            //Assert that we are removing a body that is currently attached to the controller
            Box2DXDebug.Assert(edge != null);

            //Remove edge from controller list
            if (edge.prevBody!=null)
                edge.prevBody.nextBody = edge.nextBody;
            if (edge.nextBody != null)
                edge.nextBody.prevBody = edge.prevBody;
            if (edge == _bodyList)
                _bodyList = edge.nextBody;
            --_bodyCount;

            //Remove edge from body list
            if (edge.prevController != null)
                edge.prevController.nextController = edge.nextController;
            if (edge.nextController != null)
                edge.nextController.prevController = edge.prevController;
            if (edge == body._controllerList)
                body._controllerList = edge.nextController;

            //Free the edge
            edge = null;
        }