Example #1
0
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the limit object.
        /// </summary>
        /// <param name="prefix">Prefix that identifies the exact type of the limit type.</param>
        /// <param name="limitData">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
        ///                          </param>
        public LimitCommonGUI(string prefix, LimitCommon limitData, GUILayout layout, SerializableProperties properties)
        {
            this.limitData  = limitData;
            this.properties = properties;
            this.prefix     = prefix;

            hardFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_hardLimit_Expanded", x);
                ToggleLimitFields();
            };

            contactDistanceField.OnChanged   += x => { this.limitData.contactDist = x; MarkAsModified(); };
            contactDistanceField.OnFocusLost += ConfirmModify;
            contactDistanceField.OnConfirmed += ConfirmModify;

            softFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_softLimit_Expanded", x);
                ToggleLimitFields();
            };

            restitutionField.OnChanged   += x => { this.limitData.restitution = x; MarkAsModified(); };
            restitutionField.OnFocusLost += ConfirmModify;

            springFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_spring_Expanded", x);
                ToggleLimitFields();
            };

            hardLimitLayout = layout.AddLayoutX();
            {
                hardLimitLayout.AddSpace(10);

                GUILayoutY hardLimitContentsLayout = hardLimitLayout.AddLayoutY();
                hardLimitContentsLayout.AddElement(contactDistanceField);
            }

            softLimitLayout = layout.AddLayoutX();
            layout.AddElement(softFoldout);
            {
                softLimitLayout.AddSpace(10);

                GUILayoutY softLimitContentsLayout = softLimitLayout.AddLayoutY();
                softLimitContentsLayout.AddElement(restitutionField);
                softLimitContentsLayout.AddElement(springFoldout);
                springLayout = softLimitContentsLayout.AddLayoutX();
                {
                    springLayout.AddSpace(10);

                    GUILayoutY springContentsLayout = springLayout.AddLayoutY();
                    springGUI              = new SpringGUI(limitData.spring, springContentsLayout);
                    springGUI.OnChanged   += x => { this.limitData.spring = x; MarkAsModified(); };
                    springGUI.OnConfirmed += ConfirmModify;
                }
            }
        }
        /// <summary>
        /// Creates GUI elements for fields specific to the distance joint.
        /// </summary>
        protected void BuildGUI(DistanceJoint joint)
        {
            enableMinLimitField.OnChanged += x =>
            {
                joint.EnableMinDistanceLimit = x;
                MarkAsModified();
                ConfirmModify();

                minLimitField.Active = x;
            };

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

            enableMaxLimitField.OnChanged += x =>
            {
                joint.EnableMaxDistanceLimit = x;
                MarkAsModified();
                ConfirmModify();

                maxLimitField.Active = x;
            };

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

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

            enableSpringField.OnChanged += x =>
            {
                joint.EnableSpring = x;
                MarkAsModified();
                ConfirmModify();

                springLayout.Active = x;
            };

            Layout.AddElement(enableMinLimitField);
            GUILayoutX minLimitLayout = Layout.AddLayoutX();

            {
                minLimitLayout.AddSpace(10);
                minLimitLayout.AddElement(minLimitField);
            }

            Layout.AddElement(enableMaxLimitField);
            GUILayoutX maxLimitLayout = Layout.AddLayoutX();

            {
                maxLimitLayout.AddSpace(10);
                maxLimitLayout.AddElement(maxLimitField);
            }

            Layout.AddElement(toleranceField);
            Layout.AddElement(enableSpringField);
            springLayout = Layout.AddLayoutX();
            {
                springLayout.AddSpace(10);
                springGUI              = new SpringGUI(joint.Spring, springLayout);
                springGUI.OnChanged   += x => { joint.Spring = x; MarkAsModified(); };
                springGUI.OnConfirmed += ConfirmModify;
            }

            minLimitField.Active = joint.EnableMinDistanceLimit;
            maxLimitField.Active = joint.EnableMaxDistanceLimit;
            springLayout.Active  = joint.EnableSpring;

            base.BuildGUI(joint, true);
        }
        /// <summary>
        /// Creates GUI elements for fields specific to the distance joint.
        /// </summary>
        protected void BuildGUI(DistanceJoint joint)
        {
            enableMinLimitField.OnChanged += x =>
            {
                joint.EnableMinDistanceLimit = x;
                MarkAsModified();
                ConfirmModify();

                minLimitField.Active = x;
            };

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

            enableMaxLimitField.OnChanged += x =>
            {
                joint.EnableMaxDistanceLimit = x;
                MarkAsModified();
                ConfirmModify();

                maxLimitField.Active = x;
            };

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

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

            enableSpringField.OnChanged += x =>
            {
                joint.EnableSpring = x;
                MarkAsModified();
                ConfirmModify();

                springLayout.Active = x;
            };

            Layout.AddElement(enableMinLimitField);
            GUILayoutX minLimitLayout = Layout.AddLayoutX();
            {
                minLimitLayout.AddSpace(10);
                minLimitLayout.AddElement(minLimitField);
            }

            Layout.AddElement(enableMaxLimitField);
            GUILayoutX maxLimitLayout = Layout.AddLayoutX();
            {
                maxLimitLayout.AddSpace(10);
                maxLimitLayout.AddElement(maxLimitField);
            }

            Layout.AddElement(toleranceField);
            Layout.AddElement(enableSpringField);
            springLayout = Layout.AddLayoutX();
            {
                springLayout.AddSpace(10);
                springGUI = new SpringGUI(joint.Spring, springLayout);
                springGUI.OnChanged += x => { joint.Spring = x; MarkAsModified(); };
                springGUI.OnConfirmed += ConfirmModify;
            }

            minLimitField.Active = joint.EnableMinDistanceLimit;
            maxLimitField.Active = joint.EnableMaxDistanceLimit;
            springLayout.Active = joint.EnableSpring;

            base.BuildGUI(joint, true);
        }
Example #4
0
        /// <summary>
        /// Constructs a new set of GUI elements for inspecting the limit object.
        /// </summary>
        /// <param name="prefix">Prefix that identifies the exact type of the limit type.</param>
        /// <param name="limitData">Initial values to assign to the GUI elements.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        /// <param name="properties">A set of properties that are persisted by the parent inspector. Used for saving state.
        ///                          </param>
        public LimitCommonGUI(string prefix, LimitCommonData limitData, GUILayout layout, SerializableProperties properties)
        {
            this.limitData = limitData;
            this.properties = properties;
            this.prefix = prefix;

            hardFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_hardLimit_Expanded", x);
                ToggleLimitFields();
            };

            contactDistanceField.OnChanged += x => { this.limitData.contactDist = x; MarkAsModified(); };
            contactDistanceField.OnFocusLost += ConfirmModify;
            contactDistanceField.OnConfirmed += ConfirmModify;

            softFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_softLimit_Expanded", x);
                ToggleLimitFields();
            };

            restitutionField.OnChanged += x => { this.limitData.restitution = x; MarkAsModified(); };
            restitutionField.OnFocusLost += ConfirmModify;

            springFoldout.OnToggled += x =>
            {
                properties.SetBool(prefix + "_spring_Expanded", x);
                ToggleLimitFields();
            };

            hardLimitLayout = layout.AddLayoutX();
            {
                hardLimitLayout.AddSpace(10);

                GUILayoutY hardLimitContentsLayout = hardLimitLayout.AddLayoutY();
                hardLimitContentsLayout.AddElement(contactDistanceField);
            }

            softLimitLayout = layout.AddLayoutX();
            layout.AddElement(softFoldout);
            {
                softLimitLayout.AddSpace(10);

                GUILayoutY softLimitContentsLayout = softLimitLayout.AddLayoutY();
                softLimitContentsLayout.AddElement(restitutionField);
                softLimitContentsLayout.AddElement(springFoldout);
                springLayout = softLimitContentsLayout.AddLayoutX();
                {
                    springLayout.AddSpace(10);

                    GUILayoutY springContentsLayout = springLayout.AddLayoutY();
                    springGUI = new SpringGUI(limitData.spring, springContentsLayout);
                    springGUI.OnChanged += x => { this.limitData.spring = x; MarkAsModified(); };
                    springGUI.OnConfirmed += ConfirmModify;
                }
            }
        }