/// <summary> /// Creates GUI elements for fields specific to the slider joint. /// </summary> protected void BuildGUI(SliderJoint joint) { enableLimitField.OnChanged += x => { joint.EnableLimit = x; MarkAsModified(); ConfirmModify(); ToggleLimitFields(x); }; Layout.AddElement(enableLimitField); limitLayout = Layout.AddLayoutX(); { limitLayout.AddSpace(10); GUILayoutY limitContentsLayout = limitLayout.AddLayoutY(); limitGUI = new LimitLinearRangeGUI(joint.Limit, limitContentsLayout, Persistent); limitGUI.OnChanged += (x, y) => { joint.Limit = new LimitLinearRange(x, y); MarkAsModified(); }; limitGUI.OnConfirmed += ConfirmModify; } ToggleLimitFields(joint.EnableLimit); base.BuildGUI(joint, true); }
private static void DrawSliderJoint(SliderJoint joint) { Vector3 anchor = GetAnchor(joint, JointBody.Anchor); Vector3 target = GetAnchor(joint, JointBody.Target); Vector3 normal = -joint.SceneObject.Right; if (joint.EnableLimit) { LimitLinearRange limit = joint.Limit; float max = MathEx.Min(10000.0f, limit.Upper); float min = MathEx.Clamp(limit.Lower, 0.0f, max); max = MathEx.Max(max, min); Gizmos.Color = Color.Red; Gizmos.DrawLine(anchor, anchor + normal*min); Gizmos.Color = Color.Green; Gizmos.DrawLine(anchor + normal*min, anchor + normal*max); } else { Gizmos.Color = Color.Green; float length = 100.0f; Gizmos.DrawLine(anchor, anchor + normal * length); } Gizmos.Color = Color.Yellow; Gizmos.DrawSphere(target, 0.05f); }
/// <summary> /// Updates all GUI elements from current values in the joint. /// </summary> /// <param name="joint">Joint to update the GUI from.</param> protected void Refresh(SliderJoint joint) { if (enableLimitField.Value != joint.EnableLimit) { enableLimitField.Value = joint.EnableLimit; ToggleLimitFields(joint.EnableLimit); } limitGUI.Limit = joint.Limit; base.Refresh(joint); }