Пример #1
0
        private void OnConstraintListGUI(GUISkin skin)
        {
            if (m_constraints.Count == 0)
            {
                return;
            }

            GUI.Separator();

            if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, "Constraints"), GUI.MakeLabel("Constraints", true), skin))
            {
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var constraint in m_constraints)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, constraint.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(constraint.Type.ToString(), Color.Lerp(Color.magenta, Color.black, 0.4f)) + "] " + constraint.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    var constraintTool = new ConstraintTool(constraint)
                    {
                        OnFoldoutStateChange = state => EditorUtility.SetDirty(RigidBody)
                    };
                    using (new GUI.Indent(12)) {
                        constraintTool.OnPreTargetMembersGUI(skin);
                    }
                }
            }
        }
Пример #2
0
        public void OnInspectorGUI(GUISkin skin)
        {
            if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPair == null)
            {
                PerformRemoveFromParent();
                return;
            }

            using (new GUI.Indent(16)) {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(GUI.MakeLabel("Name", true), skin.label, GUILayout.Width(64));
                    m_createConstraintData.Name = GUILayout.TextField(m_createConstraintData.Name, skin.textField, GUILayout.ExpandWidth(true));
                }
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(GUI.MakeLabel("Type", true), skin.label, GUILayout.Width(64));
                    using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.yellow, 0.1f)))
                        m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(m_createConstraintData.ConstraintType, skin.button, GUILayout.ExpandWidth(true), GUILayout.Height(18));
                }
                GUILayout.EndHorizontal();
            }

            GUI.Separator3D();

            AttachmentFrameTool.OnPreTargetMembersGUI(skin);
            AttachmentFrameTool.AttachmentPair.Update();

            m_createConstraintData.CollisionState = ConstraintTool.ConstraintCollisionsStateGUI(m_createConstraintData.CollisionState, skin);
            m_createConstraintData.SolveType      = ConstraintTool.ConstraintSolveTypeGUI(m_createConstraintData.SolveType, skin);

            GUI.Separator3D();

            var createCancelState = GUI.CreateCancelButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null &&
                                                            m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null,
                                                            skin,
                                                            "Create the constraint");

            GUI.Separator3D();

            if (createCancelState == GUI.CreateCancelState.Create)
            {
                GameObject constraintGameObject = Factory.Create(m_createConstraintData.ConstraintType,
                                                                 m_createConstraintData.AttachmentPair);
                Constraint constraint = constraintGameObject.GetComponent <Constraint>();
                constraintGameObject.name  = m_createConstraintData.Name;
                constraint.CollisionsState = m_createConstraintData.CollisionState;

                if (MakeConstraintChildToParent)
                {
                    constraintGameObject.transform.SetParent(Parent.transform);
                }

                Undo.RegisterCreatedObjectUndo(constraintGameObject, "New constraint '" + constraintGameObject.name + "' created");

                m_createConstraintData.Reset();
            }

            if (createCancelState != GUI.CreateCancelState.Nothing)
            {
                PerformRemoveFromParent();
            }
        }