/* * Draw the handle if it is enabled * */ void OnSceneGUI() { // viewport gui controls Handles.BeginGUI(); { ViewportControls.BeginArea(viewportControlsWidth, GUIAnchor.TopLeft); { GUILayout.BeginVertical(); { JointHandleToggle(); GUILayout.BeginHorizontal(); { JointHandleSizeSlider(viewportControlsWidth); } GUILayout.EndHorizontal(); CustomHandleUtilities.ViewportIntegratorFidelityControls(viewportControlsWidth); } GUILayout.EndVertical(); } ViewportControls.EndArea(); } Handles.EndGUI(); // handles if (!isHandleEnabled) { return; } Undo.SetSnapshotTarget(target, "Change Configurable Joint"); JointHandles.JointLimit(joint, jointHandleSize); EditorUtility.SetDirty(target); }
/* * Draw a joint limit gizmo for a specified part * */ public static void DrawJointHandle(BodyPart part, bool drawOpposite) { // early out if joint handles are disabled or the part is null if (!ConfigurableJointEditor.isHandleEnabled || part == null || !part.isRigidbody) { return; } // set undo snapshot BodyPart[] parts = new BodyPart[1]; if (isSymmetrical && part.oppositePart != null) { parts = new BodyPart[2]; parts[1] = part.oppositePart; parts[1].oppositePart = part; // BUG: No idea why I need to do this } parts[0] = part; Undo.SetSnapshotTarget(parts, string.Format("Change Joint Limits")); Quaternion parentRotation = (part.bone.parent == null)?Quaternion.identity:part.bone.parent.rotation; JointHandles.JointLimit(ref part.xMin, ref part.xMax, ref part.yMax, ref part.zMax, part.bone.position, parentRotation * part.initialRotation, part.jointAxis, part.jointSecondaryAxis, ConfigurableJointEditor.jointHandleSize, 1f); if (isSymmetrical && part.oppositePart != null) { // TODO: there may be something math smart to reflect axes in a general way // NOTE: this works assuming the axes have been correctly set correspondingly parts[1].xMax = part.xMax; parts[1].xMin = part.xMin; parts[1].yMax = part.yMax; parts[1].zMax = part.zMax; parentRotation = (parts[1].bone.parent == null)?Quaternion.identity:parts[1].bone.parent.rotation; JointHandles.JointLimit(ref parts[1].xMin, ref parts[1].xMax, ref parts[1].yMax, ref parts[1].zMax, parts[1].bone.position, parentRotation * parts[1].initialRotation, parts[1].jointAxis, parts[1].jointSecondaryAxis, ConfigurableJointEditor.jointHandleSize, 0.5f); part.xMax = parts[1].xMax; part.xMin = parts[1].xMin; part.yMax = parts[1].yMax; part.zMax = parts[1].zMax; } }