示例#1
0
        public void OnInspectorGUI(GUISkin skin)
        {
            using (GUI.AlignBlock.Center)
                GUILayout.Label(GUI.MakeLabel("AgXUnity Editor Settings", 24, true), skin.label);

            GUI.Separator3D();

            // Debug render manager.
            {
                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Debug render manager", 16, true), skin.label);
            }

            // BuiltInToolsTool settings GUI.
            {
                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Built in tools", 16, true), skin.label);

                GUI.Separator();

                HandleKeyHandlerGUI(GUI.MakeLabel("Select game object"), BuiltInToolsTool_SelectGameObjectKeyHandler, skin);
                HandleKeyHandlerGUI(GUI.MakeLabel("Select rigid body game object"), BuiltInToolsTool_SelectRigidBodyKeyHandler, skin);
                HandleKeyHandlerGUI(GUI.MakeLabel("Pick handler (scene view)"), BuiltInToolsTool_PickHandlerKeyHandler, skin);
            }

            GUI.Separator3D();
        }
示例#2
0
        private void HandleModeConstraintGUI(GUISkin skin)
        {
            if (ConstraintCreateTool == null)
            {
                ChangeMode(Mode.None);
                return;
            }

            GUI.Separator3D();

            ConstraintCreateTool.OnInspectorGUI(skin);
        }
示例#3
0
        private void HandleModeShapeGUI(GUISkin skin)
        {
            if (ShapeCreateTool == null)
            {
                ChangeMode(Mode.None);
                return;
            }

            GUI.Separator3D();

            ShapeCreateTool.OnInspectorGUI(skin);
        }
示例#4
0
        protected override bool OverrideOnInspectorGUI(EditorData target, GUISkin skin)
        {
            using (GUI.AlignBlock.Center)
                GUILayout.Label(GUI.MakeLabel("Editor data", 18, true), skin.label);

            GUI.Separator3D();

            const float firstLabelWidth = 190;

            GUILayout.BeginHorizontal();
            {
                TimeSpan span = TimeSpan.FromSeconds(target.SecondsSinceLastGC);
                GUILayout.Label(GUI.MakeLabel("Seconds since last GC:"), skin.label, GUILayout.Width(firstLabelWidth));
                GUILayout.Label(GUI.MakeLabel(string.Format("{0:D2}m:{1:D2}s", span.Minutes, span.Seconds), true), skin.label);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(GUI.MakeLabel("Number of data entries:"), skin.label, GUILayout.Width(firstLabelWidth));
                GUILayout.Label(GUI.MakeLabel(target.NumEntries.ToString(), true), skin.label);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(GUI.MakeLabel("Number of cached data entries:"), skin.label, GUILayout.Width(firstLabelWidth));
                GUILayout.Label(GUI.MakeLabel(target.NumCachedEntries.ToString(), true), skin.label);
            }
            GUILayout.EndHorizontal();

            GUI.Separator();
            using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.25f)))
                using (GUI.AlignBlock.Center) {
                    if (GUILayout.Button(GUI.MakeLabel("Collect garbage"), skin.button, GUILayout.Width(110)))
                    {
                        target.GC();
                    }
                }
            GUI.Separator();

            EditorUtility.SetDirty(target);

            return(true);
        }
        public override void OnPreTargetMembersGUI(GUISkin skin)
        {
            var  disabledPairs = Manager.DisabledPairs;
            bool clearPressed  = false;
            bool addPressed    = false;
            CollisionGroupEntryPair erasePair = null;

            GUILayout.Label(GUI.MakeLabel("Collision Groups Manager", 18, true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });

            GUI.Separator3D();

            GUILayout.Label(GUI.MakeLabel("Add pair", true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });

            GUILayout.BeginVertical(skin.textArea);
            {
                HandleCollisionGroupEntryPair(m_groupEntryPairToAdd, skin);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();

                    UnityEngine.GUI.enabled = m_groupEntryPairToAdd.First.Tag.Length > 0 || m_groupEntryPairToAdd.Second.Tag.Length > 0;
                    GUILayout.BeginVertical();
                    {
                        GUILayout.Space(8);
                        using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                            clearPressed = GUILayout.Button(GUI.MakeLabel("Clear"), skin.button, GUILayout.Width(64), GUILayout.Height(16));
                    }
                    GUILayout.EndVertical();

                    UnityEngine.GUI.enabled = m_groupEntryPairToAdd.First.Tag.Length > 0 && m_groupEntryPairToAdd.Second.Tag.Length > 0;
                    using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f)))
                        addPressed = GUILayout.Button(GUI.MakeLabel("Add", false, "Add pair to disabled pairs."), skin.button, GUILayout.Width(64), GUILayout.Height(22));

                    UnityEngine.GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            GUI.Separator3D();

            if (GUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Disabled Pairs [" + disabledPairs.Length + "]"), skin))
            {
                using (new GUI.Indent(12)) {
                    foreach (var disabledPair in disabledPairs)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUI.Separator(1, 10);
                            using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                                if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString()), skin.button, GUILayout.Width(18), GUILayout.Height(14)))
                                {
                                    erasePair = disabledPair;
                                }
                        }
                        GUILayout.EndHorizontal();

                        HandleCollisionGroupEntryPair(disabledPair, skin);
                    }
                }
            }

            GUI.Separator3D();

            if (clearPressed)
            {
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
            }
            if (addPressed)
            {
                Manager.SetEnablePair(m_groupEntryPairToAdd.First.Tag, m_groupEntryPairToAdd.Second.Tag, false);
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
                FoldoutDataEntry.Bool           = true;
            }
            if (erasePair != null)
            {
                if (EditorUtility.DisplayDialog("Remove pair", "Erase disabled pair: " + erasePair.First.Tag + " and " + erasePair.Second.Tag + "?", "Yes", "No"))
                {
                    Manager.SetEnablePair(erasePair.First.Tag, erasePair.Second.Tag, true);
                }
            }
        }
        private void OnContactMaterialsList(GUISkin skin)
        {
            ContactMaterial contactMaterialToAdd    = null;
            ContactMaterial contactMaterialToRemove = null;

            GUILayout.Label(GUI.MakeLabel("Contact Material Manager", 18, true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });
            GUILayout.Space(4);
            GUILayout.Label(GUI.MakeLabel("Drag and drop contact materials into the list below to add/enable the contact material in the simulation."),
                            new GUIStyle(skin.textArea)
            {
                alignment = TextAnchor.MiddleCenter
            });
            GUILayout.Space(4);

            GUI.Separator3D();

            GUILayout.BeginVertical();
            {
                if (GUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Contact Materials [" + Manager.ContactMaterialEntries.Length + "]"), skin))
                {
                    var contactMaterials = Manager.ContactMaterials;
                    using (new GUI.Indent(12)) {
                        foreach (var contactMaterial in contactMaterials)
                        {
                            GUI.Separator();

                            bool foldoutActive = false;

                            GUILayout.BeginHorizontal();
                            {
                                foldoutActive = GUI.Foldout(EditorData.Instance.GetData(Manager, contactMaterial.name), GUI.MakeLabel(contactMaterial.name), skin);
                                using (GUI.NodeListButtonColor)
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(), false, "Erase this element"),
                                                         skin.button,
                                                         new GUILayoutOption[] { GUILayout.Width(20), GUILayout.Height(14) }))
                                    {
                                        contactMaterialToRemove = contactMaterial;
                                    }
                            }
                            GUILayout.EndHorizontal();

                            if (foldoutActive)
                            {
                                using (new GUI.Indent(12))
                                    BaseEditor <ContactMaterial> .Update(contactMaterial, contactMaterial, skin);
                            }
                        }
                    }
                }
            }
            GUILayout.EndVertical();

            // Note that GetLastRect is used here and it's expecting the begin/end vertical rect.
            GUI.HandleDragDrop <ContactMaterial>(GUILayoutUtility.GetLastRect(),
                                                 Event.current,
                                                 (contactMaterial) =>
            {
                contactMaterialToAdd = contactMaterial;
            });

            GUI.Separator();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(GUI.MakeLabel("Add:"), skin.label);
                contactMaterialToAdd = EditorGUILayout.ObjectField(null, typeof(ContactMaterial), false) as ContactMaterial ?? contactMaterialToAdd;
            }
            GUILayout.EndHorizontal();

            GUI.Separator3D();

            if (contactMaterialToAdd != null)
            {
                Manager.Add(contactMaterialToAdd);
                FoldoutDataEntry.Bool = true;
            }

            if (contactMaterialToRemove != null)
            {
                Manager.Remove(contactMaterialToRemove);
            }
        }
示例#7
0
        private void HandleModeRigidBodyGUI(GUISkin skin)
        {
            GUI.Separator3D();

            using (GUI.AlignBlock.Center) {
                if (m_subMode == SubMode.SelectRigidBody)
                {
                    GUILayout.Label(GUI.MakeLabel("Select rigid body object in scene view.", true), skin.label);
                }
                else
                {
                    GUILayout.Label(GUI.MakeLabel("Select object(s) in scene view.", true), skin.label);
                }
            }

            GUI.Separator();

            bool selectionHasRigidBody         = m_selection.Find(entry => entry.Object.GetComponentInParent <RigidBody>() != null) != null;
            bool createNewRigidBodyPressed     = false;
            bool addToExistingRigidBodyPressed = false;
            bool moveToNewRigidBodyPressed     = false;

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(12);
                GUILayout.BeginVertical();
                {
                    UnityEngine.GUI.enabled       = m_selection.Count == 0 || !selectionHasRigidBody;
                    createNewRigidBodyPressed     = GUILayout.Button(GUI.MakeLabel("Create new" + (m_selection.Count == 0 ? " (empty)" : ""), false, "Create new rigid body with selected objects"), skin.button, GUILayout.Width(128));
                    UnityEngine.GUI.enabled       = m_selection.Count > 0 && Assembly.GetComponentInChildren <RigidBody>() != null;
                    addToExistingRigidBodyPressed = GUILayout.Button(GUI.MakeLabel("Add to existing", false, "Add selected objects to existing rigid body"), GUI.ConditionalCreateSelectedStyle(m_subMode == SubMode.SelectRigidBody, skin.button), GUILayout.Width(100));
                    UnityEngine.GUI.enabled       = selectionHasRigidBody;
                    moveToNewRigidBodyPressed     = GUILayout.Button(GUI.MakeLabel("Move to new", false, "Move objects that already contains a rigid body to a new rigid body"), skin.button, GUILayout.Width(85));
                    UnityEngine.GUI.enabled       = true;
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            GUI.Separator3D();

            // Creates new rigid body and move selected objects to it (as children).
            if (createNewRigidBodyPressed || moveToNewRigidBodyPressed)
            {
                CreateOrMoveToRigidBodyFromSelectionEntries(m_selection);
                m_selection.Clear();
            }
            // Toggle to select a rigid body in scene view to move the current selection to.
            else if (addToExistingRigidBodyPressed)
            {
                // This will toggle if sub-mode already is SelectRigidBody.
                ChangeSubMode(SubMode.SelectRigidBody);
            }

            // The user has chosen a rigid body to move the current selection to.
            if (m_rbSelection != null)
            {
                CreateOrMoveToRigidBodyFromSelectionEntries(m_selection, m_rbSelection.RigidBody.gameObject);
                m_selection.Clear();
                ChangeSubMode(SubMode.None);
            }
        }
        public void OnInspectorGUI(GUISkin skin)
        {
            using (GUI.AlignBlock.Center)
                GUILayout.Label(GUI.MakeLabel("AgXUnity Editor Settings", 24, true), skin.label);

            GUI.Separator3D();

            // BuiltInToolsTool settings GUI.
            {
                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Built in tools", 16, true), skin.label);

                //GUI.Separator();

                HandleKeyHandlerGUI(GUI.MakeLabel("Select game object"), BuiltInToolsTool_SelectGameObjectKeyHandler, skin);
                HandleKeyHandlerGUI(GUI.MakeLabel("Select rigid body game object"), BuiltInToolsTool_SelectRigidBodyKeyHandler, skin);
                HandleKeyHandlerGUI(GUI.MakeLabel("Pick handler (scene view)"), BuiltInToolsTool_PickHandlerKeyHandler, skin);

                GUI.Separator();
            }

            // Developer settings.
            {
                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("AGXUnity Developer", 16, true), skin.label);

                AutoFetchAGXUnityDlls = GUI.Toggle(GUI.MakeLabel("Auto fetch AGXUnity/AGXUnityEditor"),
                                                   AutoFetchAGXUnityDlls,
                                                   skin.button,
                                                   GUI.Align(skin.label, TextAnchor.MiddleLeft),
                                                   new GUILayoutOption[]
                {
                    GUILayout.Width(ToggleButtonSize),
                    GUILayout.Height(ToggleButtonSize)
                },
                                                   new GUILayoutOption[]
                {
                    GUILayout.Height(ToggleButtonSize)
                });

                using (new EditorGUI.DisabledScope(!AutoFetchAGXUnityDlls)) {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Space(ToggleButtonSize + 4);
                        GUILayout.Label(GUI.MakeLabel("Checkout directory"), skin.label, GUILayout.Width(160));
                        var statusColor = AGXUnityCheckoutDirValid ?
                                          Color.Lerp(Color.white, Color.green, 0.2f) :
                                          Color.Lerp(Color.white, Color.red, 0.2f);
                        var textFieldStyle = new GUIStyle(skin.textField);
                        var prevColor      = UnityEngine.GUI.backgroundColor;
                        UnityEngine.GUI.backgroundColor = statusColor;
                        AGXUnityCheckoutDir             = GUILayout.TextField(AGXUnityCheckoutDir, skin.textField);
                        UnityEngine.GUI.backgroundColor = prevColor;
                        if (GUILayout.Button(GUI.MakeLabel("...", false, "Open file panel"),
                                             skin.button,
                                             GUILayout.Width(28)))
                        {
                            AGXUnityCheckoutDir = EditorUtility.OpenFolderPanel("AGXUnity checkout directory", AGXUnityCheckoutDir, "");
                        }
                    }
                }

                GUI.Separator();
            }

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