/*
     * A toggle button for the joint handle
     * */
    public static void JointHandleToggle()
    {
        bool bVal = ViewportControls.OnOffToggle("Joint Limit Handles:", isHandleEnabled);

        if (bVal != isHandleEnabled)
        {
            isHandleEnabled = bVal;
        }
    }
Ejemplo n.º 2
0
 /*
  * Display viewport controls for messing with gizmos
  * */
 public static void ViewportCommonControls()
 {
     GUILayout.BeginVertical();
     {
         // only update values if they change to prevent constant updating of player pref keys
         bool bVal;
         bVal = ViewportControls.OnOffToggle("Symmetry Mode:", isSymmetrical);
         if (bVal != isSymmetrical)
         {
             isSymmetrical = bVal;
         }
         bVal = ViewportControls.OnOffToggle("Mirror Scale:", isScaleSymmetrical);
         if (bVal != isScaleSymmetrical)
         {
             isScaleSymmetrical = bVal;
         }
         bVal = ViewportControls.OnOffToggle("Shape Handles:", isShapeHandleEnabled);
         if (bVal != isShapeHandleEnabled)
         {
             isShapeHandleEnabled = bVal;
         }
         bVal = ViewportControls.OnOffToggle("Center Handles:", isCenterHandleEnabled);
         if (bVal != isCenterHandleEnabled)
         {
             isCenterHandleEnabled = bVal;
         }
         ConfigurableJointEditor.JointHandleToggle();
         GUILayout.BeginHorizontal();
         {
             ConfigurableJointEditor.JointHandleSizeSlider(viewportControlsWidth);
         }
         GUILayout.EndHorizontal();
         CustomHandleUtilities.ViewportIntegratorFidelityControls(viewportControlsWidth);
     }
     GUILayout.EndVertical();
 }
Ejemplo n.º 3
0
    /*
     * 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();
    }