void SliceJointEvent(Slice2D sliceResult) { RecalculateJoints(); // Remove Slicer Component Duplicated From Sliced Components foreach (GameObject g in sliceResult.GetGameObjects()) { List <Utilities2D.Joint2D> joints = Utilities2D.Joint2D.GetJoints(g); foreach (Utilities2D.Joint2D joint in joints) { if (Polygon2DList.CreateFromGameObject(g)[0].PointInPoly(new Vector2D(joint.anchoredJoint2D.anchor)) == false) { Destroy(joint.anchoredJoint2D); } else { if (joint.anchoredJoint2D != null && joint.anchoredJoint2D.connectedBody != null) { Sliceable2D slicer2D = joint.anchoredJoint2D.connectedBody.gameObject.GetComponent <Sliceable2D>(); if (slicer2D != null) { slicer2D.RecalculateJoints(); } } } } } if (GetRigibody() == null) { return; } // Reconnect Joints To Sliced Bodies foreach (Utilities2D.Joint2D joint in joints) { if (joint.anchoredJoint2D == null) { continue; } foreach (GameObject g in sliceResult.GetGameObjects()) { Sliceable2D slicer = g.GetComponent <Sliceable2D>(); //Polygon2D poly = slicer.shape.GetLocal(); Polygon2D polyWorld = slicer.shape.GetWorld(); Vector2D connectedAnchor2D = new Vector2D(joint.anchoredJoint2D.connectedAnchor); Vector2 connectedAnchorWorld = joint.anchoredJoint2D.connectedBody.transform.TransformPoint(connectedAnchor2D.ToVector2()); Vector2D connectedAnchorWorld2D = new Vector2D(connectedAnchorWorld); switch (joint.jointType) { case Utilities2D.Joint2D.Type.HingeJoint2D: if (polyWorld.PointInPoly(connectedAnchorWorld2D)) { joint.anchoredJoint2D.connectedBody = g.GetComponent <Rigidbody2D> (); } break; default: if (polyWorld.PointInPoly(connectedAnchorWorld2D)) { joint.anchoredJoint2D.connectedBody = g.GetComponent <Rigidbody2D> (); } else { } break; } } } }