Short version: It makes the component face in the direction it’s moving.
What seems to be happening here is the following:
First there’s a check to see if the component passed a certain threshold for moving (
if (_MoveDirection.Length() > 0.001)). You don’t want for example analog stick jitter to affect player movement. Therefore the threshold.
The following line converts the component’s movement direction to an angle (rotation around the Y axis is referred to as Yaw):
_YawOrientation = MathUtil.RadiansToDegrees((float)Math.Atan2(-_MoveDirection.Z, _MoveDirection.X) + MathUtil.PiOverTwo);
The last line converts the angle to radians and constructs a new quaternion from pitch, yaw and roll (rotations around X, Y and Z) and assigns it to the component’s rotation:
Unit.Transform.Rotation = Quaternion.RotationYawPitchRoll(MathUtil.DegreesToRadians(_YawOrientation), 0, 0);