private void DisplayJointLimits(ArticulationBody body) { ArticulationBody parentBody = ArticulationBodyEditorCommon.FindEnabledParentArticulationBody(body); // Consider that the anchors are only actually matched when in play mode. // So, if it's not play mode, we need to do that manually for the gizmos to be placed correctly. Vector3 anchorPosition; Quaternion anchorRotation; if (body.matchAnchors & !EditorApplication.isPlaying) { anchorPosition = body.transform.TransformPoint(body.anchorPosition); anchorRotation = body.transform.rotation * body.anchorRotation; } else { anchorPosition = parentBody.transform.TransformPoint(body.parentAnchorPosition); anchorRotation = parentBody.transform.rotation * body.parentAnchorRotation; } Matrix4x4 parentAnchorSpace = Matrix4x4.TRS(anchorPosition, anchorRotation, Vector3.one); // Show locked gizmo when root body or Fixed joint body if (body.isRoot || body.jointType == ArticulationJointType.FixedJoint) { m_angularLimitHandle.xMotion = (ConfigurableJointMotion)ArticulationDofLock.LockedMotion; m_angularLimitHandle.yMotion = (ConfigurableJointMotion)ArticulationDofLock.LockedMotion; m_angularLimitHandle.zMotion = (ConfigurableJointMotion)ArticulationDofLock.LockedMotion; ShowSphericalLimits(m_angularLimitHandle, body, parentAnchorSpace); return; } if (body.jointType == ArticulationJointType.PrismaticJoint) { ShowPrismaticLimits(body, parentAnchorSpace, anchorPosition, anchorRotation); return; } if (body.jointType == ArticulationJointType.RevoluteJoint) { // For the purposes of drawing Revolute limits, treat Z and Y motion as locked m_angularLimitHandle.xMotion = (ConfigurableJointMotion)body.twistLock; m_angularLimitHandle.yMotion = (ConfigurableJointMotion)ArticulationDofLock.LockedMotion; m_angularLimitHandle.zMotion = (ConfigurableJointMotion)ArticulationDofLock.LockedMotion; ShowRevoluteLimits(m_angularLimitHandle, body, parentAnchorSpace); return; } if (body.jointType == ArticulationJointType.SphericalJoint) { m_angularLimitHandle.xMotion = (ConfigurableJointMotion)body.twistLock; m_angularLimitHandle.yMotion = (ConfigurableJointMotion)body.swingYLock; m_angularLimitHandle.zMotion = (ConfigurableJointMotion)body.swingZLock; ShowSphericalLimits(m_angularLimitHandle, body, parentAnchorSpace); } }
public override void OnToolGUI(EditorWindow window) { foreach (var obj in targets) { ArticulationBody body = obj as ArticulationBody; if (body == null || body.isRoot) { continue; } ArticulationBody parentBody = ArticulationBodyEditorCommon.FindEnabledParentArticulationBody(body); { Vector3 localAnchorT = body.anchorPosition; Quaternion localAnchorR = body.anchorRotation; EditorGUI.BeginChangeCheck(); DisplayProperAnchorHandle(body, ref localAnchorT, ref localAnchorR); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Changing Articulation body anchor position/rotation"); body.anchorPosition = localAnchorT; body.anchorRotation = localAnchorR; } } if (!body.matchAnchors) { Vector3 localAnchorT = body.parentAnchorPosition; Quaternion localAnchorR = body.parentAnchorRotation; EditorGUI.BeginChangeCheck(); DisplayProperAnchorHandle(parentBody, ref localAnchorT, ref localAnchorR); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(target, "Changing Articulation body parent anchor position/rotation"); body.parentAnchorPosition = localAnchorT; body.parentAnchorRotation = localAnchorR; } } } }