public static PhysicsObjectState GetObjectState(AttachObject obj) { PhysicsObjectState state; if (obj.state == null) { state = new PhysicsObjectState(); obj.state = state; } state = (PhysicsObjectState)obj.state; return(state); }
public static void DestroyJoints(AttachObject obj) { PhysicsObjectState state = GetObjectState(obj); for (int i = 0; i < state.joints.Length; i++) { if (state.joints[i]) { GameObject.Destroy(state.joints[i]); state.joints[i] = null; } } }
// public static void UpdateJointDescriptionsFromParams(AttachObject jointed, AttachObject connected, // AttachStrategyJointDescription2D[] jointDescriptions) { // PhysicsObjectState jointedState = GetObjectState(jointed); // PhysicsObjectState connectedState = GetObjectState(connected); // int i = 0; // foreach (AttachStrategyJointDescription2D jd in jointDescriptions) { // UpdateJointDescriptionFromParams(jd, jointed, connected); // // jd.ApplyAnchors(jointedState.joints[i]); // // jd.ApplyLimits(jointedState.joints[i], jointed.gameObject, connectedState.rb); // i ++; // } // } public static void CreateOrApplyAllJoints(AttachObject jointed, AttachObject connected, AttachStrategyJointDescription[] jointDescriptions, AttachObject reference = null, bool hideJointsInInspector = true) { PhysicsObjectState jointedState = GetObjectState(jointed); if (jointedState.joints == null || jointedState.joints.Length != jointDescriptions.Length) { jointedState.joints = new Joint[jointDescriptions.Length]; } int i = 0; foreach (AttachStrategyJointDescription jd in jointDescriptions) { UpdateJointDescriptionFromParams(jd, jointed, connected, reference); jointedState.joints[i] = jd.CreateOrApply(jointed.rigidbody.gameObject, connected.rigidbody, joint: jointedState.joints[i]); jointedState.joints[i].hideFlags = hideJointsInInspector ? HideFlags.HideInInspector : HideFlags.None; i++; } }