public static Physics2DObjectState GetObjectState(AttachObject obj) { Physics2DObjectState state; if (obj.state == null) { state = new Physics2DObjectState(); obj.state = state; } state = (Physics2DObjectState)obj.state; return(state); }
public static void DestroyJoints(AttachObject obj) { Physics2DObjectState 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 UpdateAllJointDescriptionsFromParams(AttachObject jointed, AttachObject connected, // AttachStrategyJointDescription2D[] jointDescriptions) { // Physics2DObjectState jointedState = GetObjectState(jointed); // Physics2DObjectState 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, connected.rigidbody2D); // i ++; // } // } public static void CreateOrApplyAllJoints(AttachObject jointed, AttachObject connected, AttachStrategyJointDescription2D[] jointDescriptions, AttachObject reference = null, bool hideJointsInInspector = true) { Physics2DObjectState jointedState = GetObjectState(jointed); if (jointedState.joints == null || jointedState.joints.Length != jointDescriptions.Length) { jointedState.joints = new Joint2D[jointDescriptions.Length]; } int i = 0; foreach (AttachStrategyJointDescription2D jd in jointDescriptions) { UpdateJointDescriptionFromParams(jd, jointed, connected, reference); jointedState.joints[i] = jd.CreateOrApply(jointed.rigidbody2D.gameObject, connected.rigidbody2D, joint: jointedState.joints[i]); jointedState.joints[i].hideFlags = hideJointsInInspector ? HideFlags.HideInInspector : HideFlags.None; i++; } }