private void SetJoints(IEnumerable<JointInfo> joints)
{
JointInfo[] jointArray = joints != null ? joints.ToArray() : null;
// Remove joints that are not in the new collection
if (this.joints != null)
{
for (int i = this.joints.Count - 1; i >= 0; i--)
{
if (jointArray != null && jointArray.Contains(this.joints[i])) continue;
this.RemoveJoint(this.joints[i]);
}
}
// Add joints that are not in the old collection
if (jointArray != null)
{
for (int i = 0; i < jointArray.Length; i++)
{
if (this.joints != null && this.joints.Contains(jointArray[i])) continue;
JointInfo joint = jointArray[i];
if (joint.BodyA != null)
joint.BodyA.AddJoint(joint, joint.BodyB); // Allow reverse-add.
else
this.AddJoint(joint, null);
}
}
}