示例#1
0
        public void OnInspectorGUI()
        {
            if (RigidBody == null || GetChildren().Length == 0)
            {
                PerformRemoveFromParent();
                return;
            }

            var skin = InspectorEditor.Skin;

            GUILayout.Space(4);
            using (GUI.AlignBlock.Center)
                GUILayout.Label(GUI.MakeLabel("Create visual tool", 16, true), skin.label);

            GUILayout.Space(2);
            GUI.Separator();
            GUILayout.Space(4);

            foreach (var tool in GetChildren <ShapeVisualCreateTool>())
            {
                if (ShapeVisual.HasShapeVisual(tool.Shape))
                {
                    continue;
                }

                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel(tool.Shape.name, 16, true), skin.label);
                tool.OnInspectorGUI(true);
            }

            var createCancelState = GUI.CreateCancelButtons(true, skin, "Create shape visual for shapes that hasn't already got one.");

            if (createCancelState == GUI.CreateCancelState.Create)
            {
                foreach (var tool in GetChildren <ShapeVisualCreateTool>())
                {
                    if (!ShapeVisual.HasShapeVisual(tool.Shape))
                    {
                        tool.CreateShapeVisual();
                    }
                }
            }
            if (createCancelState != GUI.CreateCancelState.Nothing)
            {
                PerformRemoveFromParent();
            }
        }
示例#2
0
        public void OnInspectorGUI(bool onlyNameAndMaterial = false)
        {
            var skin = InspectorEditor.Skin;

            if (!onlyNameAndMaterial)
            {
                GUILayout.Space(4);
                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Create visual tool", 16, true), skin.label);

                GUILayout.Space(2);
                GUI.Separator();
                GUILayout.Space(4);
            }

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

            GUI.MaterialEditor(GUI.MakeLabel("Material:", true),
                               64,
                               Material,
                               skin,
                               newMaterial => Material = newMaterial);

            GUI.Separator();

            if (!onlyNameAndMaterial)
            {
                var createCancelState = GUI.CreateCancelButtons(Preview != null, skin, "Create new shape visual");
                if (createCancelState == GUI.CreateCancelState.Create)
                {
                    CreateShapeVisual();
                }
                if (createCancelState != GUI.CreateCancelState.Nothing)
                {
                    PerformRemoveFromParent();
                    return;
                }
            }
        }
        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.Synchronize();

            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();
            }
        }