Example #1
0
        /// <summary>
        /// Creates GUI elements for fields specific to the spherical joint.
        /// </summary>
        protected void BuildGUI(SphericalJoint joint)
        {
            enableLimitField.OnChanged += x =>
            {
                joint.SetFlag(SphericalJointFlag.Limit, x);
                MarkAsModified();
                ConfirmModify();

                ToggleLimitFields(x);
            };

            Layout.AddElement(enableLimitField);
            limitLayout = Layout.AddLayoutX();
            {
                limitLayout.AddSpace(10);

                GUILayoutY limitContentsLayout = limitLayout.AddLayoutY();
                limitGUI            = new LimitConeRangeGUI(joint.Limit, limitContentsLayout, Persistent);
                limitGUI.OnChanged += (x, y) =>
                {
                    joint.Limit = x;
                    joint.Limit.SetBase(y);

                    MarkAsModified();
                };
                limitGUI.OnConfirmed += ConfirmModify;
            }

            ToggleLimitFields(joint.HasFlag(SphericalJointFlag.Limit));

            base.BuildGUI(joint, true);
        }
        /// <summary>
        /// Creates GUI elements for fields specific to the spherical joint.
        /// </summary>
        protected void BuildGUI(SphericalJoint 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 LimitConeRangeGUI(joint.Limit, limitContentsLayout, Persistent);
                limitGUI.OnChanged += (x, y) =>
                {
                    joint.Limit = new LimitConeRange(x, y);

                    MarkAsModified();
                };
                limitGUI.OnConfirmed += ConfirmModify;
            }

            ToggleLimitFields(joint.EnableLimit);

            base.BuildGUI(joint, true);
        }
        /// <summary>
        /// Creates GUI elements for fields specific to the spherical joint.
        /// </summary>
        protected void BuildGUI(D6Joint joint)
        {
            for (int i = 0; i < (int)D6JointAxis.Count; i++)
            {
                D6JointAxis axis      = (D6JointAxis)i;
                string      entryName = Enum.GetName(typeof(D6JointAxis), axis);

                motionFields[i] = new GUIEnumField(typeof(D6JointMotion), new LocEdString(entryName));
                motionFields[i].OnSelectionChanged += x =>
                {
                    joint.SetMotion(axis, (D6JointMotion)x);

                    MarkAsModified();
                    ConfirmModify();
                };
            }

            linearLimitFoldout.OnToggled += x =>
            {
                linearLimitLayout.Active = x;
                Persistent.SetBool("linearLimit_Expanded", x);
            };

            twistLimitFoldout.OnToggled += x =>
            {
                twistLimitLayout.Active = x;
                Persistent.SetBool("twistLimit_Expanded", x);
            };

            swingLimitFoldout.OnToggled += x =>
            {
                swingLimitLayout.Active = x;
                Persistent.SetBool("swingLimit_Expanded", x);
            };

            driveFoldout.OnToggled += x =>
            {
                driveLayout.Active = x;
                Persistent.SetBool("drive_Expanded", x);
            };

            drivePositionField.OnChanged   += x => { joint.DrivePosition = x; MarkAsModified(); };
            drivePositionField.OnFocusLost += ConfirmModify;
            drivePositionField.OnConfirmed += ConfirmModify;

            driveRotationField.OnChanged   += x => { joint.DriveRotation = Quaternion.FromEuler(x); MarkAsModified(); };
            driveRotationField.OnFocusLost += ConfirmModify;
            driveRotationField.OnConfirmed += ConfirmModify;

            driveLinVelocityField.OnChanged   += x => { joint.DriveLinearVelocity = x; MarkAsModified(); };
            driveLinVelocityField.OnFocusLost += ConfirmModify;
            driveLinVelocityField.OnConfirmed += ConfirmModify;

            driveAngVelocityField.OnChanged   += x => { joint.DriveAngularVelocity = x; MarkAsModified(); };
            driveAngVelocityField.OnFocusLost += ConfirmModify;
            driveAngVelocityField.OnConfirmed += ConfirmModify;

            for (int i = 0; i < (int)D6JointAxis.Count; i++)
            {
                Layout.AddElement(motionFields[i]);
            }

            Layout.AddElement(linearLimitFoldout);
            linearLimitLayout = Layout.AddLayoutX();
            {
                linearLimitLayout.AddSpace(10);
                GUILayoutY linearLimitContentsLayout = linearLimitLayout.AddLayoutY();
                limitLinearGUI            = new LimitLinearGUI(joint.LimitLinear, linearLimitContentsLayout, Persistent);
                limitLinearGUI.OnChanged += (x, y) =>
                {
                    joint.LimitLinear = new LimitLinear(x, y);

                    MarkAsModified();
                };
                limitLinearGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(twistLimitFoldout);
            twistLimitLayout = Layout.AddLayoutX();
            {
                twistLimitLayout.AddSpace(10);
                GUILayoutY twistLimitContentsLayout = twistLimitLayout.AddLayoutY();
                limitTwistGUI            = new LimitAngularRangeGUI(joint.LimitTwist, twistLimitContentsLayout, Persistent);
                limitTwistGUI.OnChanged += (x, y) =>
                {
                    joint.LimitTwist = new LimitAngularRange(x, y);

                    MarkAsModified();
                };
                limitTwistGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(swingLimitFoldout);
            swingLimitLayout = Layout.AddLayoutX();
            {
                swingLimitLayout.AddSpace(10);
                GUILayoutY swingLimitContentsLayout = swingLimitLayout.AddLayoutY();
                limitSwingGUI            = new LimitConeRangeGUI(joint.LimitSwing, swingLimitContentsLayout, Persistent);
                limitSwingGUI.OnChanged += (x, y) =>
                {
                    joint.LimitSwing = new LimitConeRange(x, y);

                    MarkAsModified();
                };
                limitSwingGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(driveFoldout);
            driveLayout = Layout.AddLayoutX();
            {
                driveLayout.AddSpace(10);
                GUILayoutY driveContentsLayout = driveLayout.AddLayoutY();

                for (int i = 0; i < (int)D6JointDriveType.Count; i++)
                {
                    D6JointDriveType type = (D6JointDriveType)i;

                    drivesGUI[i]              = new D6JointDriveGUI(joint.GetDrive(type), driveContentsLayout);
                    drivesGUI[i].OnChanged   += x => { joint.SetDrive(type, new D6JointDrive(x)); MarkAsModified(); };
                    drivesGUI[i].OnConfirmed += ConfirmModify;
                }

                driveContentsLayout.AddElement(drivePositionField);
                driveContentsLayout.AddElement(driveRotationField);
                driveContentsLayout.AddElement(driveLinVelocityField);
                driveContentsLayout.AddElement(driveAngVelocityField);
            }

            linearLimitLayout.Active = Persistent.GetBool("linearLimit_Expanded");
            twistLimitLayout.Active  = Persistent.GetBool("twistLimit_Expanded");
            swingLimitLayout.Active  = Persistent.GetBool("swingLimit_Expanded");
            driveLayout.Active       = Persistent.GetBool("drive_Expanded");

            base.BuildGUI(joint, true);
        }
        /// <summary>
        /// Creates GUI elements for fields specific to the spherical joint.
        /// </summary>
        protected void BuildGUI(D6Joint joint)
        {
            for (int i = 0; i < (int) D6JointAxis.Count; i++)
            {
                D6JointAxis axis = (D6JointAxis) i;
                string entryName = Enum.GetName(typeof (D6JointAxis), axis);

                motionFields[i] = new GUIEnumField(typeof (D6JointMotion), new LocEdString(entryName));
                motionFields[i].OnSelectionChanged += x =>
                {
                    joint.SetMotion(axis, (D6JointMotion)x);

                    MarkAsModified();
                    ConfirmModify();
                };
            }

            linearLimitFoldout.OnToggled += x =>
            {
                linearLimitLayout.Active = x;
                Persistent.SetBool("linearLimit_Expanded", x);
            };

            twistLimitFoldout.OnToggled += x =>
            {
                twistLimitLayout.Active = x;
                Persistent.SetBool("twistLimit_Expanded", x);
            };

            swingLimitFoldout.OnToggled += x =>
            {
                swingLimitLayout.Active = x;
                Persistent.SetBool("swingLimit_Expanded", x);
            };

            driveFoldout.OnToggled += x =>
            {
                driveLayout.Active = x;
                Persistent.SetBool("drive_Expanded", x);
            };

            drivePositionField.OnChanged += x => { joint.DrivePosition = x; MarkAsModified(); };
            drivePositionField.OnFocusLost += ConfirmModify;
            drivePositionField.OnConfirmed += ConfirmModify;

            driveRotationField.OnChanged += x => { joint.DriveRotation = Quaternion.FromEuler(x); MarkAsModified(); };
            driveRotationField.OnFocusLost += ConfirmModify;
            driveRotationField.OnConfirmed += ConfirmModify;

            driveLinVelocityField.OnChanged += x => { joint.DriveLinearVelocity = x; MarkAsModified(); };
            driveLinVelocityField.OnFocusLost += ConfirmModify;
            driveLinVelocityField.OnConfirmed += ConfirmModify;

            driveAngVelocityField.OnChanged += x => { joint.DriveAngularVelocity = x; MarkAsModified(); };
            driveAngVelocityField.OnFocusLost += ConfirmModify;
            driveAngVelocityField.OnConfirmed += ConfirmModify;

            for (int i = 0; i < (int) D6JointAxis.Count; i++)
                Layout.AddElement(motionFields[i]);

            Layout.AddElement(linearLimitFoldout);
            linearLimitLayout = Layout.AddLayoutX();
            {
                linearLimitLayout.AddSpace(10);
                GUILayoutY linearLimitContentsLayout = linearLimitLayout.AddLayoutY();
                limitLinearGUI = new LimitLinearGUI(joint.LimitLinear, linearLimitContentsLayout, Persistent);
                limitLinearGUI.OnChanged += (x, y) =>
                {
                    joint.LimitLinear = new LimitLinear(x, y);

                    MarkAsModified();
                };
                limitLinearGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(twistLimitFoldout);
            twistLimitLayout = Layout.AddLayoutX();
            {
                twistLimitLayout.AddSpace(10);
                GUILayoutY twistLimitContentsLayout = twistLimitLayout.AddLayoutY();
                limitTwistGUI = new LimitAngularRangeGUI(joint.LimitTwist, twistLimitContentsLayout, Persistent);
                limitTwistGUI.OnChanged += (x, y) =>
                {
                    joint.LimitTwist = new LimitAngularRange(x, y);

                    MarkAsModified();
                };
                limitTwistGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(swingLimitFoldout);
            swingLimitLayout = Layout.AddLayoutX();
            {
                swingLimitLayout.AddSpace(10);
                GUILayoutY swingLimitContentsLayout = swingLimitLayout.AddLayoutY();
                limitSwingGUI = new LimitConeRangeGUI(joint.LimitSwing, swingLimitContentsLayout, Persistent);
                limitSwingGUI.OnChanged += (x, y) =>
                {
                    joint.LimitSwing = new LimitConeRange(x, y);

                    MarkAsModified();
                };
                limitSwingGUI.OnConfirmed += ConfirmModify;
            }

            Layout.AddElement(driveFoldout);
            driveLayout = Layout.AddLayoutX();
            {
                driveLayout.AddSpace(10);
                GUILayoutY driveContentsLayout = driveLayout.AddLayoutY();

                for (int i = 0; i < (int) D6JointDriveType.Count; i++)
                {
                    D6JointDriveType type = (D6JointDriveType)i;

                    drivesGUI[i] = new D6JointDriveGUI(joint.GetDrive(type), driveContentsLayout);
                    drivesGUI[i].OnChanged += x => { joint.SetDrive(type, new D6JointDrive(x)); MarkAsModified(); };
                    drivesGUI[i].OnConfirmed += ConfirmModify;
                }

                driveContentsLayout.AddElement(drivePositionField);
                driveContentsLayout.AddElement(driveRotationField);
                driveContentsLayout.AddElement(driveLinVelocityField);
                driveContentsLayout.AddElement(driveAngVelocityField);
            }

            linearLimitLayout.Active = Persistent.GetBool("linearLimit_Expanded");
            twistLimitLayout.Active = Persistent.GetBool("twistLimit_Expanded");
            swingLimitLayout.Active = Persistent.GetBool("swingLimit_Expanded");
            driveLayout.Active = Persistent.GetBool("drive_Expanded");

            base.BuildGUI(joint, true);
        }