/* * 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 custom viewport render * */ void OnSceneGUI() { // only draw handles if array parts are not null, otherwise console spams crap when component is added while object is selected if (biped.spine != null && biped.spine.Length > 0) { // get the current scaleFactor Matrix4x4 matrix = biped.transform.localToWorldMatrix; float scaleFactor = Mathf.Sqrt(VectorHelpers.MaxValue(new Vector3( new Vector3(matrix.m00, matrix.m01, matrix.m02).sqrMagnitude, new Vector3(matrix.m10, matrix.m11, matrix.m12).sqrMagnitude, new Vector3(matrix.m20, matrix.m21, matrix.m22).sqrMagnitude))); // draw balls and lines for all defined parts Handles.color = ballsColor; foreach (BodyPart part in biped.allParts) { DrawBall(part, scaleFactor); } // draw a shape gizmo for each body part Handles.color = shapeColor; foreach (BodyPart part in biped.allParts) { BodyPartEditor.DrawShapeHandle(part, false); } // draw joint gizmos for all the body parts foreach (BodyPart part in biped.allParts) { BodyPartEditor.DrawJointHandle(part, false); } } // begin GUI or transform handles will be disabled Handles.BeginGUI(); // create the viewport controls ViewportControls.BeginArea(BodyPartEditor.viewportControlsWidth, GUIAnchor.TopLeft); { // common controls for BodyParts (shape, center, joints) BodyPartEditor.ViewportCommonControls(); // only update values if they change to prevent constant updating of player pref keys float fVal; GUILayout.BeginHorizontal(); { GUILayout.Label(string.Format("Transform Display Size: {0:0.00}", ballSize), GUILayout.Width(BodyPartEditor.viewportControlsWidth * 0.65f)); fVal = GUILayout.HorizontalSlider(ballSize, 0f, 1f); if (fVal != ballSize) { ballSize = fVal; } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(string.Format("Body Mass: {0:0.00}", biped.mass), GUILayout.Width(BodyPartEditor.viewportControlsWidth * 0.65f)); fVal = GUILayout.HorizontalSlider(biped.mass, 1f, 500f); if (fVal != biped.mass) { biped.mass = fVal; biped.DistributeMass(); } } GUILayout.EndHorizontal(); // if the editor is playing, then create testing controls if (Application.isPlaying) { // padding after previous controls GUILayout.Space(ViewportControls.viewportPadding * 2f); // only display ragdoll controls if minimum requirements have been met if (biped.ValidateMinimumRequirements()) { // if the biped is currently ragdoll, then create a button to remove the ragdoll if (biped.isRagdoll) { if (GUILayout.Button("Remove Ragdoll")) { biped.RemoveRagdoll(); } } // otherwise create a button to turn the biped into a ragdoll else { if (GUILayout.Button("Create Ragdoll")) { biped.CreateRagdoll(BodyPartEditor.jointResistance, 1f); } } // only update an active ragdoll's spring value if the resistance slider changes float oldResist = BodyPartEditor.jointResistance; float oldForce = BodyPartEditor.maxForce; BodyPartEditor.ViewportResistanceSlider(); BodyPartEditor.ViewportMaxForceSlider(); if ((oldResist != BodyPartEditor.jointResistance || oldForce != BodyPartEditor.maxForce) && biped.isRagdoll) { JointDrive drive; foreach (BodyPart part in biped.allParts) { if (part == null || part.joint == null) { continue; } drive = part.joint.slerpDrive; drive.maximumForce = BodyPartEditor.maxForce; drive.positionSpring = BodyPartEditor.jointResistance; part.joint.slerpDrive = drive; } } // if the biped is out of ragdoll, include a button to return to the snapshot if (!biped.isRagdoll) { if (GUILayout.Button("Restore Pose to Snapshot")) { foreach (BodyPart part in biped.allParts) { if (part == null) { continue; } part.ResetToInitialRotation(); part.ResetToPositionSnapshot(); } } } } else { GUILayout.Label("Minimum biped definition not specified. Please stop the game and ensure that biped minimum requirements have been met."); } } // otherwise, create additional setup controls else { GUILayout.Label("Bone Naming Convention:"); GUILayout.BeginVertical(); { namingConvention = (DCCApplication)GUILayout.SelectionGrid((int)namingConvention, System.Enum.GetNames(typeof(DCCApplication)), 2); if (GUILayout.Button(string.Format("Set Up Biped Using {0} Names", namingConvention))) { biped.AutomateSetup(namingConvention); } } GUILayout.EndVertical(); } } ViewportControls.EndArea(); // display symmetry status at the top of the viewport BodyPartEditor.ViewportStatus(); // finish GUI Handles.EndGUI(); }
/* * Draw custom viewport render * */ void OnSceneGUI() { // draw the shape gizmo Handles.color = shapeColor; DrawShapeHandle(part, isSymmetrical); // draw the joint handle DrawJointHandle(part, isSymmetrical); // begin GUI or transform handles will be disabled Handles.BeginGUI(); // create the viewport controls ViewportControls.BeginArea(viewportControlsWidth, GUIAnchor.TopLeft); { ViewportCommonControls(); part.isRigidbody = ViewportControls.OnOffToggle("Is Rigidbody:", part.isRigidbody); part.isCollider = ViewportControls.OnOffToggle("Is Collider:", part.isCollider); if (isSymmetrical && part.oppositePart != null) { part.oppositePart.isRigidbody = part.isRigidbody; part.oppositePart.isCollider = part.isCollider; } ViewportShapeControls(part); // if the editor is playing, then create testing controls if (Application.isPlaying) { // padding after previous controls GUILayout.Space(ViewportControls.viewportPadding * 2f); // create a button to test the joint if it does not currently have one if (part.joint == null) { if (part.isRigidbody && GUILayout.Button("Test Joint")) { // the BodyPart needs to have a parentPart defined in order to test if (part.parentPart == null) { Debug.LogError("Cannot test part: its parentPart is null.", this); } else { if (part.bone.rigidbody == null) { part.AddRigidbody(); } else { part.bone.rigidbody.isKinematic = false; } if (part.parentPart.bone.rigidbody == null) { part.parentPart.AddRigidbody(); part.parentPart.bone.rigidbody.isKinematic = true; } if (part.bone.collider == null) { part.AddCollider(); } part.ConnectToParent(jointResistance, maxForce); } } } // otherwise create a button to remove the joint else { if (GUILayout.Button("Remove Joint")) { Destroy(part.joint); Destroy(part.rigidbody); Destroy(part.collider); part.ResetToInitialRotation(); } } // only update the joint's spring and force values if the slider values have changed if (part.isRigidbody) { float oldResist = jointResistance; float oldForce = maxForce; ViewportResistanceSlider(); ViewportMaxForceSlider(); if ((oldResist != jointResistance || oldForce != maxForce) && part.joint != null) { JointDrive drive = part.joint.slerpDrive; drive.maximumForce = maxForce; drive.positionSpring = jointResistance; part.joint.slerpDrive = drive; } } } } ViewportControls.EndArea(); // display symmetry status at the top of the viewport ViewportStatus(); // finish GUI Handles.EndGUI(); }