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(); } }
public void OnInspectorGUI() { if (HandleKeyEscape(false)) { return; } var skin = InspectorEditor.Skin; InspectorGUI.OnDropdownToolBegin(GetCurrentStateInfo()); UnityEngine.GUI.enabled = m_selection.Count > 0; m_buttons.OnGUI(Event.current); UnityEngine.GUI.enabled = true; InspectorGUI.OnDropdownToolEnd(); EditorUtility.SetDirty(Parent); // Call this before we exit since it'll remove the visual primitive // if no shape button currently is selected. var vp = GetSelectedButtonVisualPrimitive(); if (m_buttons.Selected == null) { return; } if (m_selection.Count == 0 || m_buttons.Selected.State.Axis == ShapeInitializationData.Axes.None) { return; } var shapesInitData = ShapeInitializationData.Create(m_selection.ToArray()); if (shapesInitData.Length == 0) { return; } var shapeInitData = shapesInitData[0]; var axisData = shapeInitData.FindAxisData(m_buttons.Selected.State.Axis, m_buttons.Selected.State.ExpandRadius); UpdateVisualPrimitive(vp, shapeInitData, axisData); if (m_buttons.Selected.State.CreatePressed) { if (m_buttons.Selected.State.ShapeType == ShapeType.Box) { CreateShape <Box>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, box => { box.HalfExtents = shapeInitData.LocalExtents; shapeInitData.SetDefaultPositionRotation(box.gameObject); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.Cylinder) { CreateShape <Cylinder>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, cylinder => { cylinder.Radius = axisData.Radius; cylinder.Height = axisData.Height; shapeInitData.SetPositionRotation(cylinder.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.HollowCylinder) { CreateShape <HollowCylinder>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, hollowCylinder => { hollowCylinder.Thickness = axisData.Radius / 10f; // Arbitrary base thickness hollowCylinder.Radius = axisData.Radius; hollowCylinder.Height = axisData.Height; shapeInitData.SetPositionRotation(hollowCylinder.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.Cone) { CreateShape <Cone>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, cone => { cone.TopRadius = axisData.Radius; cone.BottomRadius = axisData.Radius; cone.Height = axisData.Height; shapeInitData.SetPositionRotation(cone.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.HollowCone) { CreateShape <HollowCone>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, hollowCone => { hollowCone.Thickness = axisData.Radius / 10f; // Arbitrary base thickness hollowCone.TopRadius = axisData.Radius / 2f; // Arbitrary base top radius hollowCone.BottomRadius = axisData.Radius; hollowCone.Height = axisData.Height; shapeInitData.SetPositionRotation(hollowCone.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.Capsule) { CreateShape <Capsule>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, capsule => { capsule.Radius = axisData.Radius; capsule.Height = axisData.Height; shapeInitData.SetPositionRotation(capsule.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.Sphere) { CreateShape <Sphere>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, sphere => { sphere.Radius = axisData.Radius; shapeInitData.SetPositionRotation(sphere.gameObject, axisData.Direction); }); } else if (m_buttons.Selected.State.ShapeType == ShapeType.Mesh) { CreateShape <Mesh>(shapeInitData, m_buttons.Selected.State.ShapeAsParent, mesh => { mesh.SetSourceObject(shapeInitData.Filter.sharedMesh); // We don't want to set the position given the center of the bounds // since we're one-to-one with the mesh filter. mesh.transform.position = shapeInitData.Filter.transform.position; mesh.transform.rotation = shapeInitData.Filter.transform.rotation; }); } Reset(); } }
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(); }
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(); }
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(); }