public void OnInspectorGUI(bool onlyNameAndMaterial = false)
        {
            if (!onlyNameAndMaterial)
            {
                InspectorGUI.OnDropdownToolBegin("Create visual representation of this shape.");
            }

            Name = EditorGUILayout.TextField(GUI.MakeLabel("Name"),
                                             Name,
                                             InspectorEditor.Skin.TextField);

            InspectorGUI.UnityMaterial(GUI.MakeLabel("Material"),
                                       Material,
                                       newMaterial => Material = newMaterial);

            if (!onlyNameAndMaterial)
            {
                var createCancelState = InspectorGUI.PositiveNegativeButtons(Preview != null,
                                                                             "Create",
                                                                             "Create new shape visual.",
                                                                             "Cancel");

                InspectorGUI.OnDropdownToolEnd();

                if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive)
                {
                    CreateShapeVisual();
                }
                if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral)
                {
                    PerformRemoveFromParent();
                }
            }
        }
        public void OnInspectorGUI()
        {
            if (RigidBody == null || GetChildren().Length == 0)
            {
                PerformRemoveFromParent();
                return;
            }

            var skin = InspectorEditor.Skin;

            InspectorGUI.OnDropdownToolBegin("Create visual representation of this rigid body given all supported shapes.");

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

                EditorGUILayout.PrefixLabel(GUI.MakeLabel(tool.Shape.name,
                                                          true),
                                            skin.Label);
                using (InspectorGUI.IndentScope.Single)
                    tool.OnInspectorGUI(true);
            }

            var createCancelState = InspectorGUI.PositiveNegativeButtons(true,
                                                                         "Create",
                                                                         "Create shape visual for shapes that hasn't already got one.",
                                                                         "Cancel");

            if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                foreach (var tool in GetChildren <ShapeVisualCreateTool>())
                {
                    if (!ShapeVisual.HasShapeVisual(tool.Shape))
                    {
                        tool.CreateShapeVisual();
                    }
                }
            }

            InspectorGUI.OnDropdownToolEnd();

            if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral)
            {
                PerformRemoveFromParent();
            }
        }
Beispiel #3
0
        public void OnInspectorGUI()
        {
            InspectorGUI.OnDropdownToolBegin($"Disable collisions between {m_mainObject.name} and other objects selected in Scene View.");

            var skin         = InspectorEditor.Skin;
            var emptyContent = GUI.MakeLabel(" ");

            EditorGUILayout.LabelField(GUI.MakeLabel("Disable: ", true),
                                       SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject),
                                       skin.TextArea);


            EditorGUILayout.LabelField(emptyContent,
                                       GUI.MakeLabel(GUI.Symbols.ArrowLeftRight.ToString()));

            if (m_selected.Count == 0)
            {
                EditorGUILayout.LabelField(emptyContent,
                                           GUI.MakeLabel("Select object(s) in scene view" + AwaitingUserActionDots()),
                                           skin.TextArea);
            }
            else
            {
                int removeIndex = -1;
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    GUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(emptyContent,
                                                   SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]),
                                                   skin.TextArea);
                        if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                true,
                                                "Remove pair.",
                                                GUILayout.Width(14)))
                        {
                            removeIndex = i;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (removeIndex >= 0)
                {
                    m_selected.RemoveAt(removeIndex);
                }
            }

            var applyCancelState = InspectorGUI.PositiveNegativeButtons(m_selected.Count > 0,
                                                                        "Apply",
                                                                        "Apply current configuration.",
                                                                        "Cancel");

            if (applyCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                string selectedGroupName   = m_mainObject.GetInstanceID().ToString();
                string mainObjectGroupName = "";
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    mainObjectGroupName += m_selected[i].GetInstanceID().ToString() +
                                           (i != m_selected.Count - 1 ? "_" : "");
                }

                Undo.SetCurrentGroupName("Disabling collisions");
                var undoGroupId = Undo.GetCurrentGroup();

                if (m_mainObject.GetComponent <CollisionGroups>() == null)
                {
                    Undo.AddComponent <CollisionGroups>(m_mainObject);
                }

                Undo.RecordObject(m_mainObject.GetComponent <CollisionGroups>(), "Adding collision group");
                m_mainObject.GetComponent <CollisionGroups>().AddGroup(mainObjectGroupName,
                                                                       ShouldPropagateToChildren(m_mainObject));
                foreach (var selected in m_selected)
                {
                    if (selected.GetComponent <CollisionGroups>() == null)
                    {
                        Undo.AddComponent <CollisionGroups>(selected);
                    }
                    Undo.RecordObject(selected.GetComponent <CollisionGroups>(), "Adding collision group");
                    selected.GetComponent <CollisionGroups>().AddGroup(selectedGroupName,
                                                                       ShouldPropagateToChildren(selected));
                }

                // TopMenu.GetOrCreate works with Undo.
                Undo.RecordObject(TopMenu.GetOrCreateUniqueGameObject <CollisionGroupsManager>(),
                                  "Adding collision group to manager.");

                CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false);

                Undo.CollapseUndoOperations(undoGroupId);

                PerformRemoveFromParent();
            }
            else if (applyCancelState == InspectorGUI.PositiveNegativeResult.Negative)
            {
                PerformRemoveFromParent();
            }

            InspectorGUI.OnDropdownToolEnd();
        }
Beispiel #4
0
        public void OnInspectorGUI()
        {
            if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPairs[0] == null)
            {
                PerformRemoveFromParent();
                return;
            }

            InspectorGUI.OnDropdownToolBegin("Create constraint given type and use additional tools to " +
                                             "configure the constraint frames.");

            var skin = InspectorEditor.Skin;

            m_createConstraintData.Name = EditorGUILayout.TextField(GUI.MakeLabel("Name", true),
                                                                    m_createConstraintData.Name,
                                                                    skin.TextField);


#if UNITY_2018_1_OR_NEWER
            m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true),
                                                                                              m_createConstraintData.ConstraintType,
                                                                                              val => (ConstraintType)val != ConstraintType.Unknown,
                                                                                              false,
                                                                                              skin.Popup);
#else
            m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true),
                                                                                              m_createConstraintData.ConstraintType,
                                                                                              skin.Popup);
#endif

            AttachmentFrameTool.OnPreTargetMembersGUI();
            AttachmentFrameTool.AttachmentPairs[0].Synchronize();

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

            var createCancelState = InspectorGUI.PositiveNegativeButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null &&
                                                                         m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null,
                                                                         "Create",
                                                                         "Create the constraint",
                                                                         "Cancel");

            if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                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_onCreate?.Invoke(constraint);

                m_createConstraintData.Reset();
            }

            if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral)
            {
                PerformRemoveFromParent();
            }

            InspectorGUI.OnDropdownToolEnd();
        }
Beispiel #5
0
        private void MeshOptionsGUI()
        {
            InspectorGUI.Separator();

            using (new GUI.EnabledBlock(!EditorApplication.isPlayingOrWillChangePlaymode)) {
                if (InspectorGUI.Foldout(GetEditorData(Mesh), GUI.MakeLabel("Options")))
                {
                    using (InspectorGUI.IndentScope.Single) {
                        InspectorEditor.DrawMembersGUI(Targets, t => (t as AGXUnity.Collide.Mesh).Options);
                        var applyResetResult = InspectorGUI.PositiveNegativeButtons(UnityEngine.GUI.enabled,
                                                                                    "Apply",
                                                                                    "Apply the changes",
                                                                                    "Reset",
                                                                                    "Delete collision meshes and reset mesh options values to default.");
                        if (applyResetResult == InspectorGUI.PositiveNegativeResult.Positive)
                        {
                            var meshes = GetTargets <AGXUnity.Collide.Mesh>().ToArray();
                            var collisionMeshGenerator = new AGXUnity.Collide.CollisionMeshGenerator();
                            var generatorStartTime     = EditorApplication.timeSinceStartup;
                            collisionMeshGenerator.GenerateAsync(meshes);
                            var isCanceled = false;
                            while (!isCanceled && collisionMeshGenerator.IsRunning)
                            {
                                var progressBarTitle = $"Generating collision meshes: {(int)( EditorApplication.timeSinceStartup - generatorStartTime )} s";
                                var progressBarInfo  = string.Empty;
                                var progress         = collisionMeshGenerator.Progress;
                                isCanceled = EditorUtility.DisplayCancelableProgressBar(progressBarTitle, progressBarInfo, progress);
                                if (!isCanceled)
                                {
                                    System.Threading.Thread.Sleep(50);
                                }
                            }

                            EditorUtility.ClearProgressBar();

                            if (isCanceled)
                            {
                                CanceledAsyncCollisionMeshGeneretors.RegisterCanceled(collisionMeshGenerator);
                            }
                            else
                            {
                                var results = collisionMeshGenerator.CollectResults();
                                using (new Utils.UndoCollapseBlock("Apply collision mesh data")) {
                                    foreach (var result in results)
                                    {
                                        Undo.RecordObject(result.Mesh, "Collision Meshes");
                                        result.Mesh.Options = result.Options;
                                        result.Mesh.PrecomputedCollisionMeshes = result.CollisionMeshes;
                                    }
                                }

                                var hasPrefabAssetBeenChanged = results.Any(result =>
                                                                            PrefabUtility.GetCorrespondingObjectFromOriginalSource(result.Mesh.gameObject) == null &&
                                                                            PrefabUtility.GetPrefabInstanceHandle(result.Mesh.gameObject) == null);
                                // Trying to dirty gizmos rendering of all affected prefab instances.
                                // We don't have to dirty them all but it's hard to determine where
                                // the instance is located in the hierarchy.
                                if (hasPrefabAssetBeenChanged)
                                {
                                    var allMeshes = Object.FindObjectsOfType <AGXUnity.Collide.Mesh>();
                                    foreach (var m in allMeshes)
                                    {
                                        m.OnPrecomputedCollisionMeshDataDirty();
                                    }
                                }
                            }

                            collisionMeshGenerator = null;

                            GUIUtility.ExitGUI();
                        }
                        else if (applyResetResult == InspectorGUI.PositiveNegativeResult.Negative &&
                                 EditorUtility.DisplayDialog("Reset collision meshes to default",
                                                             "Destroy collision meshes and reset mesh options to default?",
                                                             "Yes", "Cancel"))
                        {
                            var meshes = GetTargets <AGXUnity.Collide.Mesh>().ToArray();
                            using (new Utils.UndoCollapseBlock("Reset collision mesh data")) {
                                for (int i = 0; i < meshes.Length; ++i)
                                {
                                    var mesh = meshes[i];
                                    Undo.RecordObject(mesh, "Resetting collision mesh data");
                                    mesh.DestroyCollisionMeshes();
                                    if (mesh.Options != null)
                                    {
                                        Undo.RecordObject(mesh, "Resetting mesh options to default");
                                        mesh.Options.ResetToDesfault();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        public void OnInspectorGUI()
        {
            if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPairs[0] == null)
            {
                PerformRemoveFromParent();
                return;
            }

            InspectorGUI.OnDropdownToolBegin("Create constraint given type and use additional tools to " +
                                             "configure the constraint frames.");

            var skin = InspectorEditor.Skin;

            m_createConstraintData.Name = EditorGUILayout.TextField(GUI.MakeLabel("Name", true),
                                                                    m_createConstraintData.Name,
                                                                    skin.TextField);


#if UNITY_2018_1_OR_NEWER
            m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true),
                                                                                              m_createConstraintData.ConstraintType,
                                                                                              val => (ConstraintType)val != ConstraintType.Unknown,
                                                                                              false,
                                                                                              skin.Popup);
#else
            m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(GUI.MakeLabel("Type", true),
                                                                                              m_createConstraintData.ConstraintType,
                                                                                              skin.Popup);
#endif

            AttachmentFrameTool.OnPreTargetMembersGUI();
            AttachmentFrameTool.AttachmentPairs[0].Synchronize();

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

            if (Parent != null)
            {
                MakeConstraintChildToParent = InspectorGUI.Toggle(GUI.MakeLabel($"Create as child",
                                                                                true,
                                                                                $"Add the created constraint game object as child " +
                                                                                $"to \"{Parent.name}\". If false, the game object is " +
                                                                                $"created without a parent or under the prefab root if " +
                                                                                $"created inside a prefab stage."),
                                                                  MakeConstraintChildToParent);
            }

            var createCancelState = InspectorGUI.PositiveNegativeButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null &&
                                                                         m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null,
                                                                         "Create",
                                                                         "Create the constraint",
                                                                         "Cancel");
            if (createCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                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);
                }
                else
                {
                    // If we're in the Prefab Stage this call will add the constraint
                    // game object as child of the root prefab.
                    UnityEditor.SceneManagement.StageUtility.PlaceGameObjectInCurrentStage(constraintGameObject);
                }

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

                m_onCreate?.Invoke(constraint);

                m_createConstraintData.Reset();
            }

            if (createCancelState != InspectorGUI.PositiveNegativeResult.Neutral)
            {
                PerformRemoveFromParent();
            }

            InspectorGUI.OnDropdownToolEnd();
        }
        public override void OnPreTargetMembersGUI()
        {
            var  skin          = InspectorEditor.Skin;
            var  disabledPairs = Manager.DisabledPairs;
            bool clearPressed  = false;
            bool addPressed    = false;
            CollisionGroupEntryPair erasePair = null;

            GUILayout.Label(GUI.MakeLabel("Add pair",
                                          true),
                            skin.LabelMiddleCenter);

            GUILayout.BeginVertical(skin.TextArea);
            {
                HandleCollisionGroupEntryPair(m_groupEntryPairToAdd);

                var buttonState = InspectorGUI.PositiveNegativeButtons(m_groupEntryPairToAdd.First.Tag.Length > 0 ||
                                                                       m_groupEntryPairToAdd.Second.Tag.Length > 0,
                                                                       "Add",
                                                                       "Add pair to disabled pairs.",
                                                                       "Clear");
                addPressed   = buttonState == InspectorGUI.PositiveNegativeResult.Positive;
                clearPressed = buttonState == InspectorGUI.PositiveNegativeResult.Negative;
            }
            GUILayout.EndVertical();

            if (InspectorGUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Disabled Pairs [" + disabledPairs.Length + "]")))
            {
                using (InspectorGUI.IndentScope.Single) {
                    foreach (var disabledPair in disabledPairs)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            InspectorGUI.Separator(1, EditorGUIUtility.singleLineHeight);

                            if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                    true,
                                                    "Remove pair from list.",
                                                    GUILayout.Width(18)))
                            {
                                erasePair = disabledPair;
                            }
                        }
                        GUILayout.EndHorizontal();

                        HandleCollisionGroupEntryPair(disabledPair);

                        // TODO GUI: Maybe unnecessary space with correct separator.
                        GUILayout.Space(6.0f);
                    }
                }
            }

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