public override void OnPostTargetMembersGUI() { var skin = InspectorEditor.Skin; var beginWinches = GetTargets <Wire, WireWinch>(wire => wire.BeginWinch).Where(winch => winch != null); var endWinches = GetTargets <Wire, WireWinch>(wire => wire.EndWinch).Where(winch => winch != null); if (beginWinches.Count() > 0) { GUILayout.Label(GUI.MakeLabel("Begin winch", true), skin.Label); using (InspectorGUI.IndentScope.Single) { if (beginWinches.Count() != NumTargets) { InspectorGUI.WarningLabel("Not all selected wires has a begin winch."); } InspectorEditor.DrawMembersGUI(beginWinches.ToArray()); } } if (endWinches.Count() > 0) { GUILayout.Label(GUI.MakeLabel("End winch", true), skin.Label); using (InspectorGUI.IndentScope.Single) { if (endWinches.Count() != NumTargets) { InspectorGUI.WarningLabel("Not all selected wires has an end winch."); } InspectorEditor.DrawMembersGUI(endWinches.ToArray()); } } }
public override void OnPreTargetMembersGUI() { if (m_edgeIssues.Count > 0) { foreach (var issue in m_edgeIssues) { InspectorGUI.WarningLabel(issue); } } HandleLineToolInspectorGUI(TopEdgeLineTool, "Top Edge"); HandleLineToolInspectorGUI(CuttingEdgeLineTool, "Cutting Edge"); HandleLineToolInspectorGUI(CuttingDirectionLineTool, "Cutting Direction"); m_requestEdgeValidate = true; }
public void OnInspectorGUI() { if (Mode == ToolMode.Direction) { StartFrameNameId = "Frame"; } StartFrameToolEnable = Line.Valid; EndFrameToolEnable = Line.Valid; bool toggleCreateEdge = false; bool toggleFlipDirection = false; bool toggleRenderAsArrow = false; bool showTools = !EditorApplication.isPlaying; if (showTools) { var toolButtonData = new List <InspectorGUI.ToolButtonData>(); toolButtonData.Add(InspectorGUI.ToolButtonData.Create(ToolIcon.VisualizeLineDirection, RenderAsArrow, "Visualize line direction.", () => toggleRenderAsArrow = true, Mode != ToolMode.Direction)); toolButtonData.Add(InspectorGUI.ToolButtonData.Create(ToolIcon.FlipDirection, false, "Flip direction.", () => toggleFlipDirection = true, Line.Valid)); toolButtonData.Add(InspectorGUI.ToolButtonData.Create(ToolIcon.FindTransformGivenEdge, EdgeDetectionToolEnable, "Find line given edge.", () => toggleCreateEdge = true)); InspectorGUI.ToolButtons(toolButtonData.ToArray()); } if (toggleCreateEdge) { EdgeDetectionToolEnable = !EdgeDetectionToolEnable; } if (toggleFlipDirection && EditorUtility.DisplayDialog("Line direction", "Flip direction of " + Name + "?", "Yes", "No")) { StartFrameToolEnable = false; if (Mode == ToolMode.Direction) { Line.End.Position = Line.End.Position - 2.0f * Line.Length * Line.Direction; Line.Start.Rotation = Quaternion.Euler(-Line.Start.Rotation.eulerAngles); Line.End.Rotation = Quaternion.Euler(-Line.End.Rotation.eulerAngles); } else { var tmp = Line.Start; Line.Start = Line.End; Line.End = tmp; } } if (toggleRenderAsArrow) { RenderAsArrow = !RenderAsArrow; } if (!Line.Valid) { InspectorGUI.WarningLabel(Name + " isn't created - use Tools to configure."); } if (StartFrameToolEnable) { if (InspectorGUI.Foldout(GetToggleData(StartFrameNameId), GUI.MakeLabel(StartFrameNameId, true))) { StartFrameTool.ForceDisableTransformHandle = EditorApplication.isPlaying; using (new GUI.EnabledBlock(!EditorApplication.isPlaying)) InspectorGUI.HandleFrame(StartFrameTool.Frame, 1); } } if (EndFrameToolEnable) { if (InspectorGUI.Foldout(GetToggleData(EndFrameNameId), GUI.MakeLabel(EndFrameNameId, true))) { EndFrameTool.ForceDisableTransformHandle = EditorApplication.isPlaying; using (new GUI.EnabledBlock(!EditorApplication.isPlaying)) InspectorGUI.HandleFrame(EndFrameTool.Frame, 1); } } Synchronize(); }
public override void OnPreTargetMembersGUI() { var skin = InspectorEditor.Skin; var constraints = GetTargets <Constraint>().ToArray(); var refConstraint = constraints[0]; var differentTypes = false; var anyUnknownType = constraints.Any(c => c.Type == ConstraintType.Unknown); for (int i = 1; i < constraints.Length; ++i) { differentTypes = differentTypes || refConstraint.Type != constraints[i].Type; } // Render AttachmentPair GUI. ConstraintAttachmentFrameTool.OnPreTargetMembersGUI(); Undo.RecordObjects(constraints, "ConstraintTool"); UnityEngine.GUI.changed = false; // The constraint type is Unknown when, e.g., go.AddComponent<Constraint>() // or when the constraint has been reset. If any of the selected constraints // is of type Unknown, we exit the GUI here. if (!ConstraintTypeGUI(constraints, differentTypes)) { return; } EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.CollisionsState != constraint.CollisionsState); var collisionsState = ConstraintCollisionsStateGUI(refConstraint.CollisionsState); 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); EditorGUI.showMixedValue = false; if (UnityEngine.GUI.changed) { foreach (var constraint in constraints) { constraint.SolveType = solveType; } UnityEngine.GUI.changed = false; } EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.ConnectedFrameNativeSyncEnabled != constraint.ConnectedFrameNativeSyncEnabled); var frameNativeSync = ConstraintConnectedFrameSyncGUI(refConstraint.ConnectedFrameNativeSyncEnabled); EditorGUI.showMixedValue = false; if (UnityEngine.GUI.changed) { foreach (var constraint in constraints) { constraint.ConnectedFrameNativeSyncEnabled = frameNativeSync; } UnityEngine.GUI.changed = false; } if (differentTypes) { InspectorGUI.WarningLabel("Constraints are of different types.\nRow data editing not supported."); 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>(); foreach (ConstraintUtils.ConstraintRowParser.RowType rowType in Enum.GetValues(typeof(ConstraintUtils.ConstraintRowParser.RowType))) { if (!InspectorGUI.Foldout(selected("ec_" + rowType.ToString()), GUI.MakeLabel(rowType.ToString() + " properties", true))) { continue; } using (InspectorGUI.IndentScope.Single) { var refTransOrRotRowData = constraintsParser[0][rowType]; foreach (var wrapper in ecRowDataWrappers) { if (!InspectorEditor.ShouldBeShownInInspector(wrapper.Member)) { continue; } for (int i = 0; i < 3; ++i) { var rowDataInstances = (from constraintParser in constraintsParser where constraintParser[rowType][i] != null select constraintParser[rowType][i].RowData).ToArray(); using (new GUI.EnabledBlock(refTransOrRotRowData[i] != null)) { var labelContent = i == 0 ? InspectorGUI.MakeLabel(wrapper.Member) : null; var fieldContent = GUI.MakeLabel(RowLabels[i], RowColors[i]); if (wrapper.IsType <float>()) { EditorGUI.showMixedValue = !wrapper.AreValuesEqual(rowDataInstances); var value = InspectorGUI.CustomFloatField(labelContent, fieldContent, wrapper.Get <float>(refTransOrRotRowData[i]?.RowData)); if (UnityEngine.GUI.changed) { foreach (var constraintParser in constraintsParser) { wrapper.ConditionalSet(constraintParser[rowType][i]?.RowData, value); } } } else if (wrapper.IsType <RangeReal>()) { EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min, wrapper.Get <RangeReal>(rowData).Min)) || rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max, wrapper.Get <RangeReal>(rowData).Max)); var rangeChangeData = InspectorGUI.RangeRealField(labelContent, wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData), GUI.MakeLabel(RowLabels[i], RowColors[i])); if (rangeChangeData.MinChanged || rangeChangeData.MaxChanged) { foreach (var constraintParser in constraintsParser) { var range = wrapper.Get <RangeReal>(constraintParser[rowType][i].RowData); if (rangeChangeData.MinChanged) { range.Min = rangeChangeData.Min; } if (rangeChangeData.MaxChanged) { range.Max = rangeChangeData.Max; } // 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; } } // For type wrappers. } // Indentation. } // For Translational, Rotational. var ecControllers = refConstraint.GetElementaryConstraintControllers(); if (ecControllers.Length > 0 && InspectorGUI.Foldout(selected("controllers"), GUI.MakeLabel("Controllers", true))) { using (InspectorGUI.IndentScope.Single) { foreach (var refController in ecControllers) { var controllerType = refController.GetControllerType(); var controllerTypeTag = controllerType.ToString()[0].ToString(); var controllerName = ConstraintUtils.FindName(refController); if (controllerName.EndsWith(" Controller")) { controllerName = controllerName.Remove(controllerName.LastIndexOf(" Controller")); } var controllerLabel = GUI.MakeLabel((controllerType == Constraint.ControllerType.Rotational ? GUI.Symbols.CircleArrowAcw.ToString() + " " : GUI.Symbols.ArrowRight.ToString() + " ") + controllerName, true); if (!InspectorGUI.Foldout(selected(controllerTypeTag + controllerName), controllerLabel)) { continue; } var controllers = (from constraint in constraints from controller in constraint.GetElementaryConstraintControllers() where controller.GetType() == refController.GetType() && controller.GetControllerType() == refController.GetControllerType() select controller).ToArray(); using (InspectorGUI.IndentScope.Single) { InspectorEditor.DrawMembersGUI(controllers); InspectorEditor.DrawMembersGUI(controllers, controller => (controller as ElementaryConstraint).RowData[0]); } } } } }
public override void OnPreTargetMembersGUI() { var refMaterial = Material; var mixedPreset = Targets.Any(target => (target as DeformableTerrainMaterial).PresetName != refMaterial.PresetName); using (new InspectorGUI.IndentScope((InspectorGUI.IndentScope.Level > 0 ? -1 : 0))) { var resetButtonWidth = EditorGUIUtility.singleLineHeight; var rect = EditorGUILayout.GetControlRect(); var totalRectWidth = rect.width; var availablePresets = DeformableTerrainMaterial.GetAvailablePresets().ToArray(); var presetIndex = FindPresetIndex(availablePresets, refMaterial.PresetName); var invalidPreset = presetIndex < 0; EditorGUI.showMixedValue = mixedPreset || invalidPreset; if (invalidPreset) { InspectorGUI.WarningLabel($"Material preset name {refMaterial.PresetName} doesn't exist in the material presets library."); } rect.width = EditorGUIUtility.labelWidth; EditorGUI.PrefixLabel(rect, GUI.MakeLabel("Preset"), InspectorEditor.Skin.Label); rect.x += rect.width; rect.width = totalRectWidth - EditorGUIUtility.labelWidth - resetButtonWidth; EditorGUI.BeginChangeCheck(); var newPresetIndex = EditorGUI.Popup(rect, Mathf.Max(presetIndex, 0), availablePresets, InspectorEditor.Skin.Popup); if (EditorGUI.EndChangeCheck() && invalidPreset) { invalidPreset = false; } EditorGUI.showMixedValue = false; rect.x += rect.width; rect.width = resetButtonWidth; var resetButtonPressed = InspectorGUI.Button(rect, MiscIcon.ResetDefault, !invalidPreset, $"Reset values to default for preset: {refMaterial.PresetName}", 0.9f); if (!invalidPreset && newPresetIndex != presetIndex && EditorUtility.DisplayDialog("Library preset -> " + availablePresets[newPresetIndex], $"Change preset from {refMaterial.PresetName} to {availablePresets[ newPresetIndex ]}?\n" + "All current values will be overwritten.", "Yes", "No")) { foreach (var material in GetTargets <DeformableTerrainMaterial>()) { material.SetPresetNameAndUpdateValues(availablePresets[newPresetIndex]); } } if (resetButtonPressed && EditorUtility.DisplayDialog("Reset values to default", $"Reset preset {refMaterial.PresetName} to default?", "Yes", "No")) { foreach (var material in GetTargets <DeformableTerrainMaterial>()) { material.ResetToPresetDefault(); } } InspectorGUI.Separator(); } }