public static Constraint.ECollisionsState ConstraintCollisionsStateGUI(Constraint.ECollisionsState state, GUISkin skin) { bool guiWasEnabled = UnityEngine.GUI.enabled; using (new GUI.Indent(12)) { GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Disable collisions: ", true), GUI.Align(skin.label, TextAnchor.MiddleLeft), new GUILayoutOption[] { GUILayout.Width(140), GUILayout.Height(25) }); UnityEngine.GUI.enabled = !EditorApplication.isPlaying; if (GUILayout.Button(GUI.MakeLabel("Rb " + GUI.Symbols.Synchronized.ToString() + " Rb", false, "Disable all shapes in rigid body 1 against all shapes in rigid body 2."), GUI.ConditionalCreateSelectedStyle(state == Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2, skin.button), new GUILayoutOption[] { GUILayout.Width(76), GUILayout.Height(25) })) { state = state == Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2 ? Constraint.ECollisionsState.KeepExternalState : Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2; } if (GUILayout.Button(GUI.MakeLabel("Ref " + GUI.Symbols.Synchronized.ToString() + " Con", false, "Disable Reference object vs. Connected object."), GUI.ConditionalCreateSelectedStyle(state == Constraint.ECollisionsState.DisableReferenceVsConnected, skin.button), new GUILayoutOption[] { GUILayout.Width(76), GUILayout.Height(25) })) { state = state == Constraint.ECollisionsState.DisableReferenceVsConnected ? Constraint.ECollisionsState.KeepExternalState : Constraint.ECollisionsState.DisableReferenceVsConnected; } UnityEngine.GUI.enabled = guiWasEnabled; } GUILayout.EndHorizontal(); } return(state); }
public override void OnPreTargetMembersGUI(GUISkin skin) { // Possible undo performed that deleted the constraint. Remove us. if (Constraint == null) { PerformRemoveFromParent(); return; } GUILayout.Label(GUI.MakeLabel(Constraint.Type.ToString(), 24, true), GUI.Align(skin.label, TextAnchor.MiddleCenter)); GUI.Separator(); // Render AttachmentPair GUI. base.OnPreTargetMembersGUI(skin); GUI.Separator(); Constraint.CollisionsState = ConstraintCollisionsStateGUI(Constraint.CollisionsState, skin); Constraint.SolveType = ConstraintSolveTypeGUI(Constraint.SolveType, skin); GUI.Separator(); Constraint.ConnectedFrameNativeSyncEnabled = ConstraintConnectedFrameSyncGUI(Constraint.ConnectedFrameNativeSyncEnabled, skin); GUI.Separator(); ConstraintRowsGUI(skin); }
public override void OnPreTargetMembersGUI() { var skin = InspectorEditor.Skin; GUILayout.Label(GUI.MakeLabel("Debug render manager", 16, true), GUI.Align(skin.label, TextAnchor.MiddleCenter)); GUI.Separator(); var newRenderState = GUI.Toggle(GUI.MakeLabel("Debug render shapes"), Manager.RenderShapes, skin.button, skin.label); if (newRenderState != Manager.RenderShapes) { Manager.RenderShapes = newRenderState; EditorUtility.SetDirty(Manager); } GUI.MaterialEditor(GUI.MakeLabel("Shape material"), 100, Manager.ShapeRenderMaterial, skin, newMaterial => Manager.ShapeRenderMaterial = newMaterial, true); GUI.Separator(); using (new GUILayout.HorizontalScope()) { Manager.RenderContacts = GUI.Toggle(GUI.MakeLabel("Render contacts"), Manager.RenderContacts, skin.button, skin.label); Manager.ContactColor = EditorGUILayout.ColorField(Manager.ContactColor); } Manager.ContactScale = EditorGUILayout.Slider(GUI.MakeLabel("Scale"), Manager.ContactScale, 0.0f, 1.0f); GUI.Separator(); Manager.ColorizeBodies = GUI.Toggle(GUI.MakeLabel("Colorize bodies", false, "Every rigid body instance will be rendered with a unique color (wire framed)."), Manager.ColorizeBodies, skin.button, skin.label); Manager.HighlightMouseOverObject = GUI.Toggle(GUI.MakeLabel("Highlight mouse over object", false, "Highlight mouse over object in scene view."), Manager.HighlightMouseOverObject, skin.button, skin.label); Manager.IncludeInBuild = GUI.Toggle(GUI.MakeLabel("Include in build", false, "Include debug rendering when building the project."), Manager.IncludeInBuild, skin.button, skin.label); }
public void OnInspectorGUI(GUISkin skin) { GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Disable: ", true), skin.label); GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject), skin.textField); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); GUILayout.Label(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString()), skin.label); GUILayout.BeginVertical(); { if (m_selected.Count == 0) { GUILayout.Label(GUI.MakeLabel("None", true), skin.label, GUILayout.Width(180)); } else { int removeIndex = -1; for (int i = 0; i < m_selected.Count; ++i) { GUILayout.BeginHorizontal(); { GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]), GUI.Align(skin.textField, TextAnchor.MiddleLeft), GUILayout.Height(20)); using (GUI.NodeListButtonColor) if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString()), skin.button, GUILayout.Width(18), GUILayout.Height(18))) { removeIndex = i; } } GUILayout.EndHorizontal(); } if (removeIndex >= 0) { m_selected.RemoveAt(removeIndex); } } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.Space(12); bool applyPressed = false; bool cancelPressed = false; GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); UnityEngine.GUI.enabled = m_selected.Count > 0; applyPressed = GUILayout.Button(GUI.MakeLabel("Apply", true, "Apply current configuration"), skin.button, GUILayout.Width(86), GUILayout.Height(26)); UnityEngine.GUI.enabled = true; GUILayout.BeginVertical(); { GUILayout.Space(11); cancelPressed = GUILayout.Button(GUI.MakeLabel("Cancel", false, "Cancel/reset"), skin.button, GUILayout.Width(64), GUILayout.Height(18)); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (applyPressed) { 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 ? "_" : ""); } m_mainObject.GetOrCreateComponent <CollisionGroups>().AddGroup(mainObjectGroupName, ShouldPropagateToChildren(m_mainObject)); foreach (var selected in m_selected) { selected.GetOrCreateComponent <CollisionGroups>().AddGroup(selectedGroupName, ShouldPropagateToChildren(selected)); } CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false); PerformRemoveFromParent(); } else if (cancelPressed) { PerformRemoveFromParent(); } }
private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler, GUISkin skin) { const int keyButtonWidth = 90; GUILayout.BeginHorizontal(); { keyHandler.Enable = GUI.Toggle(name, keyHandler.Enable, skin.button, GUI.Align(skin.label, TextAnchor.MiddleLeft), new GUILayoutOption[] { GUILayout.Width(ToggleButtonSize), GUILayout.Height(ToggleButtonSize) }, new GUILayoutOption[] { GUILayout.Height(ToggleButtonSize) }); GUILayout.FlexibleSpace(); UnityEngine.GUI.enabled = keyHandler.Enable; for (int iKey = 0; iKey < keyHandler.NumKeyCodes; ++iKey) { GUIContent buttonLabel = keyHandler.IsDetectingKey(iKey) ? GUI.MakeLabel("Detecting...") : GUI.MakeLabel(keyHandler.Keys[iKey].ToString()); bool toggleDetecting = GUILayout.Button(buttonLabel, skin.button, GUILayout.Width(keyButtonWidth), GUILayout.Height(ToggleButtonSize)); if (toggleDetecting) { keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey); } } Rect dropDownButtonRect = new Rect(); GUILayout.BeginVertical(GUILayout.Height(ToggleButtonSize)); { GUIStyle tmp = new GUIStyle(skin.button); tmp.fontSize = 6; m_showDropDown = GUILayout.Button(GUI.MakeLabel("v", true), tmp, GUILayout.Width(16), GUILayout.Height(14)) ? !m_showDropDown : m_showDropDown; dropDownButtonRect = GUILayoutUtility.GetLastRect(); GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); UnityEngine.GUI.enabled = true; if (m_showDropDown && dropDownButtonRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(GUI.MakeLabel("Reset to default"), false, () => { if (EditorUtility.DisplayDialog("Reset to default", "Reset key(s) to default?", "OK", "Cancel")) { keyHandler.ResetToDefault(); } }); menu.AddItem(GUI.MakeLabel("Add key"), false, () => { keyHandler.Add(KeyCode.None); }); if (keyHandler.NumKeyCodes > 1) { menu.AddItem(GUI.MakeLabel("Remove key"), false, () => { if (EditorUtility.DisplayDialog("Remove key", "Remove key: " + keyHandler[keyHandler.NumKeyCodes - 1].ToString() + "?", "OK", "Cancel")) { keyHandler.Remove(keyHandler.NumKeyCodes - 1); } }); } menu.ShowAsContext(); } } GUILayout.EndHorizontal(); if (UnityEngine.GUI.changed) { EditorUtility.SetDirty(this); } }
public override void OnPreTargetMembersGUI() { // TODO: Improvements. // - "Copy-paste" shape. // 1. Select object with primitive shape(s) // 2. Select object to copy the shape(s) to // - Move from-to existing bodies or create a new body. // - Mesh object operations. // * Simplify assembly // * Multi-select to create meshes // - Inspect element (hold 'i'). if (!AGXUnity.Utils.Math.IsUniform(Assembly.transform.lossyScale, 1.0E-3f)) { Debug.LogWarning("Scale of AGXUnity.Assembly transform isn't uniform. If a child rigid body is moving under this transform the (visual) behavior is undefined.", Assembly); } var skin = InspectorEditor.Skin; if (!IsMultiSelect) { bool rbButtonPressed = false; bool shapeButtonPressed = false; bool constraintButtonPressed = false; GUI.ToolsLabel(skin); GUILayout.BeginHorizontal(); { GUILayout.Space(12); using (GUI.ToolButtonData.ColorBlock) { rbButtonPressed = GUILayout.Button(GUI.MakeLabel("RB", true, "Assembly rigid body tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.RigidBody, skin.button), GUILayout.Width(30f), GUI.ToolButtonData.Height); shapeButtonPressed = GUILayout.Button(GUI.MakeLabel("Shape", true, "Assembly shape tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Shape, skin.button), GUILayout.Width(54f), GUI.ToolButtonData.Height); constraintButtonPressed = GUILayout.Button(GUI.MakeLabel("Constraint", true, "Assembly constraint tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Constraint, skin.button), GUILayout.Width(80f), GUI.ToolButtonData.Height); } } GUILayout.EndHorizontal(); HandleModeGUI(); if (rbButtonPressed) { ChangeMode(Mode.RigidBody); } if (shapeButtonPressed) { ChangeMode(Mode.Shape); } if (constraintButtonPressed) { ChangeMode(Mode.Constraint); } } else { GUILayout.Label(GUI.MakeLabel("Assemblies", 24, true), GUI.Align(skin.label, TextAnchor.MiddleCenter)); } GUI.Separator(); OnObjectListsGUI(this); }
public override void OnPreTargetMembersGUI() { var skin = InspectorEditor.Skin; var constraints = GetTargets <Constraint>().ToArray(); var refConstraint = constraints[0]; var differentTypes = false; for (int i = 1; i < constraints.Length; ++i) { differentTypes = differentTypes || refConstraint.Type != constraints[i].Type; } GUILayout.Label(GUI.MakeLabel((differentTypes ? "Constraints" : refConstraint.Type.ToString() + (IsMultiSelect ? "s" : string.Empty)), 24, true), GUI.Align(skin.label, TextAnchor.MiddleCenter)); GUI.Separator(); // Render AttachmentPair GUI. ConstraintAttachmentFrameTool.OnPreTargetMembersGUI(); Undo.RecordObjects(constraints, "ConstraintTool"); UnityEngine.GUI.changed = false; EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.CollisionsState != constraint.CollisionsState); var collisionsState = ConstraintCollisionsStateGUI(refConstraint.CollisionsState, skin); EditorGUI.showMixedValue = false; if (UnityEngine.GUI.changed) { foreach (var constraint in constraints) { constraint.CollisionsState = collisionsState; } UnityEngine.GUI.changed = false; } EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.SolveType != constraint.SolveType); var solveType = ConstraintSolveTypeGUI(refConstraint.SolveType, skin); EditorGUI.showMixedValue = false; if (UnityEngine.GUI.changed) { foreach (var constraint in constraints) { constraint.SolveType = solveType; } UnityEngine.GUI.changed = false; } GUI.Separator(); EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.ConnectedFrameNativeSyncEnabled != constraint.ConnectedFrameNativeSyncEnabled); var frameNativeSync = ConstraintConnectedFrameSyncGUI(refConstraint.ConnectedFrameNativeSyncEnabled, skin); EditorGUI.showMixedValue = false; if (UnityEngine.GUI.changed) { foreach (var constraint in constraints) { constraint.ConnectedFrameNativeSyncEnabled = frameNativeSync; } UnityEngine.GUI.changed = false; } if (differentTypes) { GUI.WarningLabel("Constraints are of different types.\nRow data editing not supported.", skin); return; } Func <string, EditorDataEntry> selected = (id) => { return(EditorData.Instance.GetData(refConstraint, id, entry => entry.Bool = false)); }; var constraintsParser = (from constraint in constraints select ConstraintUtils.ConstraintRowParser.Create(constraint)).ToArray(); var allElementaryConstraints = constraints.SelectMany(constraint => constraint.GetOrdinaryElementaryConstraints()).ToArray(); Undo.RecordObjects(allElementaryConstraints, "ConstraintTool"); var ecRowDataWrappers = InvokeWrapper.FindFieldsAndProperties <ElementaryConstraintRowData>(); GUI.Separator(); foreach (ConstraintUtils.ConstraintRowParser.RowType rowType in Enum.GetValues(typeof(ConstraintUtils.ConstraintRowParser.RowType))) { if (!GUI.Foldout(selected("ec_" + rowType.ToString()), GUI.MakeLabel(rowType.ToString() + " properties", true), skin)) { GUI.Separator(); continue; } using (new GUI.Indent(12)) { var refTransOrRotRowData = constraintsParser[0][rowType]; foreach (var wrapper in ecRowDataWrappers) { if (!InspectorEditor.ShouldBeShownInInspector(wrapper.Member)) { continue; } using (new GUILayout.HorizontalScope()) { GUILayout.Label(InspectorGUI.MakeLabel(wrapper.Member), skin.label); GUILayout.FlexibleSpace(); using (new GUILayout.VerticalScope()) { for (int i = 0; i < 3; ++i) { var rowDataInstances = (from constraintParser in constraintsParser where constraintParser[rowType][i] != null select constraintParser[rowType][i].RowData).ToArray(); // TODO: This could probably be replaced by using InspectorEditor.HandleType // with a tweak. We use wrapper.Get<type>( foo.RowData ) while our // drawers uses wrapper.Get<type>(). // UPDATE: Probably not worth it because we have to override all labels // written by our default drawers. // **************************************************************************** //var objects = ( from constraintParser // in constraintsParser // where constraintParser[ rowType ][ i ] != null // select constraintParser[ rowType ][ i ].RowData ).ToArray(); //using ( new GUILayout.HorizontalScope() ) //using ( new GUI.EnabledBlock( refTransOrRotRowData[ i ] != null ) ) { // RowLabel( i, skin ); // InspectorEditor.HandleType( wrapper, objects ); //} // **************************************************************************** using (new GUILayout.HorizontalScope()) using (new GUI.EnabledBlock(refTransOrRotRowData[i] != null)) { RowLabel(i, skin); // Handling type float, e.g., compliance and damping. if (wrapper.IsType <float>()) { EditorGUI.showMixedValue = !wrapper.AreValuesEqual(rowDataInstances); var value = EditorGUILayout.FloatField(wrapper.Get <float>(refTransOrRotRowData[i]?.RowData)); if (UnityEngine.GUI.changed) { foreach (var constraintParser in constraintsParser) { wrapper.ConditionalSet(constraintParser[rowType][i].RowData, value); } UnityEngine.GUI.changed = false; } EditorGUI.showMixedValue = false; } // Handling type RangeReal, e.g., force range. // Note: During multi-selection we don't want to write, e.g., Min from // reference row data when value for Max is changed. else if (wrapper.IsType <RangeReal>()) { EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min, wrapper.Get <RangeReal>(rowData).Min)); var forceRangeMin = EditorGUILayout.FloatField(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min, GUILayout.MaxWidth(128)); var forceRangeMinChanged = UnityEngine.GUI.changed; EditorGUI.showMixedValue = false; UnityEngine.GUI.changed = false; EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max, wrapper.Get <RangeReal>(rowData).Max)); var forceRangeMax = EditorGUILayout.FloatField(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max, GUILayout.MaxWidth(128)); if (forceRangeMinChanged || UnityEngine.GUI.changed) { foreach (var constraintParser in constraintsParser) { var range = wrapper.Get <RangeReal>(constraintParser[rowType][i].RowData); if (forceRangeMinChanged) { range.Min = forceRangeMin; } if (UnityEngine.GUI.changed) { range.Max = forceRangeMax; } // Validation of Min > Max has to go somewhere else because if e.g., // Min = 50 and the user wants to type Max = 200 we're receiving // Max = 2 as the user types. wrapper.ConditionalSet(constraintParser[rowType][i].RowData, range); } UnityEngine.GUI.changed = false; EditorGUI.showMixedValue = false; } } // IsType RangeReal. }// Horizontal and GUI Enabled blocks. } // For U, V, N. } // Right align vertical scope. } // Horizontal with flexible space for alignment. GUI.Separator(); } // For type wrappers. } // Indentation. GUI.Separator(); } // For Translational, Rotational. if (GUI.Foldout(selected("controllers"), GUI.MakeLabel("Controllers", true), skin)) { GUI.Separator(); using (new GUI.Indent(12)) { foreach (var refController in refConstraint.GetElementaryConstraintControllers()) { var controllerType = refController.GetControllerType(); var controllerTypeTag = controllerType.ToString()[0].ToString(); var controllerName = ConstraintUtils.FindName(refController); string dimString = "[" + GUI.AddColorTag(controllerTypeTag, controllerType == Constraint.ControllerType.Rotational ? Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f) : Color.Lerp(UnityEngine.GUI.color, Color.green, 0.75f)) + "] "; if (!GUI.Foldout(selected(controllerTypeTag + controllerName), GUI.MakeLabel(dimString + controllerName, true), skin)) { GUI.Separator(); continue; } var controllers = (from constraint in constraints from controller in constraint.GetElementaryConstraintControllers() where controller.GetType() == refController.GetType() select controller).ToArray(); using (new GUI.Indent(12)) { InspectorEditor.DrawMembersGUI(controllers); GUI.Separator(); InspectorEditor.DrawMembersGUI(controllers, controller => (controller as ElementaryConstraint).RowData[0]); } GUI.Separator(); } } } }