private static void DrawHeader() { BGEditorUtility.HorizontalBox(() => { GUILayout.Label(" "); }); GUI.DrawTexture(GUILayoutUtility.GetLastRect(), boxWithBorderImage); var rect = new Rect(new Vector2(40, 10), new Vector2(headerImage.width * HeaderHeight / (float)headerImage.height, HeaderHeight)); GUI.DrawTexture(rect, headerImage); if (tree.DependsOnType != null) { GUI.Label(new Rect(rect) { x = rect.xMax + 10, height = 16, width = 400, y = rect.y - 2 }, "Filter: Dependent on [" + tree.DependsOnType.Name + "]", filterStyle); } }
private void OnGUI() { BGEditorUtility.HorizontalBox(() => { EditorGUILayout.LabelField("Point index", GUILayout.Width(100)); var newValue = EditorGUILayout.IntSlider(current, 0, curve.PointsCount - 1, GUILayout.Width(200)); if (current != newValue) { current = newValue; action((BGCurvePointComponent)curve[newValue]); } if (GUILayout.Button("Close", GUILayout.Width(50))) { instance.Close(); } }); }
internal void OnInspectorGui(BGCurvePointI point, int index, BGCurveSettings settings) { var mode2D = point.Curve.Mode2D; //point transform if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined && point.PointTransform != null) { var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point); if (referenceToPoint == null) { point.PointTransform.gameObject.AddComponent <BGCurveReferenceToPoint>().Point = point; } } BGEditorUtility.HorizontalBox(() => { if (editorSelection != null) { editorSelection.InspectorSelectionRect(point); } BGEditorUtility.VerticalBox(() => { BGEditorUtility.SwapLabelWidth(60, () => { if (!settings.ShowPointPosition && !settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { //nothing to show- only label EditorGUILayout.LabelField("Point " + index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { //control type if (settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { point.ControlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Point " + index, point.ControlType); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } //position if (settings.ShowPointPosition) { if (!settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { PositionField("Point " + index, point, mode2D, index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { PositionField("Pos", point, mode2D, index); } } } }); // control positions if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent && settings.ShowPointControlPositions) { // 1st ControlField(point, mode2D, 1); // 2nd ControlField(point, mode2D, 2); } //transform if (settings.ShowTransformField) { BGEditorUtility.ComponentField("Transform", point.PointTransform, transform => { if (transform != null) { Undo.RecordObject(transform, "Object moved"); if (point.Curve.PointsMode != BGCurve.PointsModeEnum.Inlined) { Undo.AddComponent <BGCurveReferenceToPoint>(transform.gameObject).Point = point; } } if (point.PointTransform != null) { var referenceToPoint = BGCurveReferenceToPoint.GetReferenceToPoint(point); if (referenceToPoint != null) { Undo.DestroyObjectImmediate(referenceToPoint); } } point.PointTransform = transform; }); } //fields if (point.Curve.FieldsCount > 0) { ShowFields(point); } BGEditorUtility.EndIndent(1); }); }); }
// ================================================================================ Inspector public override void OnInspectorGui() { var settings = Settings; editorSelection.Reset(); // ======================================== Top section InspectorTopSection(); // ======================================== Points GUILayout.Space(5); if (Curve.PointsCount > 0) { BGEditorUtility.VerticalBox(() => { var temp = BGCurveSettingsForEditor.DisableInspectorPointMenu; BGCurveSettingsForEditor.DisableInspectorPointMenu = BGEditorUtility.ButtonOnOff(ref temp, "Points menu [" + Curve.PointsCount + "]", "Show points in Editor inspector", HiddenPointMenuColor, new GUIContent("Show", "Click to show points menu"), new GUIContent("Hide", "Click to hide points menu"), () => { const string title = "Reverse points"; if (!GUILayout.Button(new GUIContent(title, "Reverse all points, but keep curve intact"))) { return; } if (Curve.PointsCount < 2) { BGEditorUtility.Inform(title, "There should be at least 2 points. Curve has " + Curve.PointsCount); return; } if (!BGEditorUtility.Confirm(title, "Are you sure you want to reverse the order of " + Curve.PointsCount + " points? Curve will remain intact.", "Reverse")) { return; } Curve.Reverse(); }); //show points! if (!BGCurveSettingsForEditor.DisableInspectorPointMenu) { SwapVector2Labels(Curve.Mode2D, () => Curve.ForEach((point, index, count) => editorPoint.OnInspectorGui(point, index, settings))); } }); // ======================================== Selections operations editorSelection.InspectorSelectionOperations(); //warning BGEditorUtility.HelpBox("Selection mode is on", MessageType.Warning, !editorSelection.Changed && editorSelection.HasSelected()); } else { BGEditorUtility.HorizontalBox(() => { EditorGUILayout.LabelField("No points!"); if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new point at (0,0,0) local coordinates")) { BGCurveEditor.AddPoint(Curve, new BGCurvePoint(Curve, Vector3.zero, settings.ControlType, Vector3.right, Vector3.left), 0); } }); } if (!editorSelection.Changed) { return; } Editor.Repaint(); SceneView.RepaintAll(); }
//OnInspectorGui for selection public void InspectorSelectionOperations() { BGEditorUtility.VerticalBox(() => { // ================================================ Global operations BGEditorUtility.HorizontalBox(() => { BGEditorUtility.SwapLabelWidth(80, () => EditorGUILayout.LabelField("Selected (" + points.Count + ")")); if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete selected points")) { if (!DeleteSelected()) { return; } } GUILayout.Space(4); if (BGEditorUtility.ButtonWithIcon(selectAllTexture, "Select all points", 35)) { Changed = Changed || points.Count != curve.PointsCount; points.Clear(); foreach (var point1 in curve.Points) { points.Add(point1); } } GUILayout.Space(4); if (BGEditorUtility.ButtonWithIcon(deselectAllTexture, "Deselect all points", 35)) { Clear(); } }); // ================================================ Selections operations // skip mouse buttons events which change selection if (Changed) { return; } GUILayout.Space(5); if (HasSelected()) { BGEditorUtility.SwapGuiBackgroundColor(SelectedBackgroundColor, () => { BGEditorUtility.VerticalBox(() => { var averagePositionSelected = GetAveragePosition(); // ===================================================== Control handles BGEditorUtility.Horizontal(() => { controlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Controls", controlType); if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "Set control type for all selected points", 44)) { return; } SetControlTypeForSelected(controlType); }); // ===================================================== Average positions & delete BGEditorUtility.Vector3Field("Average position", "Average points position. Change several points positions at once, keeping distance difference intact", averagePositionSelected, newAverage => { var delta = newAverage - averagePositionSelected; curve.Transaction(() => { foreach (var point in points) { point.PositionWorld += delta; } }); }); // ===================================================== Set position directly BGEditorUtility.Vector3Field("Set position", "Set points position directly", averagePositionSelected, newPosition => { curve.Transaction(() => { if (BGEditorUtility.AnyChange(averagePositionSelected.x, newPosition.x)) { SetX(newPosition.x); } if (BGEditorUtility.AnyChange(averagePositionSelected.y, newPosition.y)) { SetY(newPosition.y); } if (BGEditorUtility.AnyChange(averagePositionSelected.z, newPosition.z)) { SetZ(newPosition.z); } }); }); // ===================================================== Set control positions directly var count = 0; var averageControl1Sum = Vector3.zero; var averageControl2Sum = Vector3.zero; foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { count++; averageControl1Sum += point.ControlFirstLocal; averageControl2Sum += point.ControlSecondLocal; } if (count == 0) { return; } //has points with bezier controls BGEditorUtility.Vector3Field("Set Control 1", "Set 1st control position directly", averageControl1Sum / count, newPosition => { curve.Transaction( () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { point.ControlFirstLocal = newPosition; } }); }); BGEditorUtility.Vector3Field("Set Control 2", "Set 2nd control position directly", averageControl2Sum / count, newPosition => { curve.Transaction( () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)) { point.ControlSecondLocal = newPosition; } }); }); }); }); } else { BGEditorUtility.HelpBox("Hold shift to use rectangular selection\r\nClick or click+drag over tick icons to (de)select points", MessageType.Info, curve.PointsCount > 0); } }); }
// ================================================================================ Inspector public override void OnInspectorGui() { BGEditorUtility.Assign(ref whiteTexture, () => BGEditorUtility.Texture1X1(Color.white)); components = Curve.GetComponents <BGCc>(); var length = components.Length; tree.Refresh(components); if (tree.InitException != null) { EditorGUILayout.HelpBox("There was an error initializing editors for component's Tree View: " + tree.InitException.Message + "\r\n\r\nYou still can use default Unity's editors for components below.", MessageType.Error); return; } var hasError = HasError; var hasWarning = HasWarning; BGEditorUtility.HorizontalBox(() => { EditorGUILayout.LabelField("Components: " + length + " (" + (hasError ? "Error" : "Ok") + ")"); GUILayout.FlexibleSpace(); // turn on/off handles var handlesOff = BGCurveSettingsForEditor.CcInspectorHandlesOff; if (BGEditorUtility.ButtonWithIcon( handlesOff ? BGBinaryResources.BGHandlesOff123 : BGBinaryResources.BGHandlesOn123, "Turn on/off handles settings in Inspector")) { BGCurveSettingsForEditor.CcInspectorHandlesOff = !BGCurveSettingsForEditor.CcInspectorHandlesOff; } EditorGUILayout.Separator(); // turn on/off colored tree if (BGEditorUtility.ButtonWithIcon(customEditorsOn ? BGBinaryResources.BGOn123: BGBinaryResources.BGOff123, "Use custom UI for components (colored tree) and hide standard unity editors for components")) { customEditorsOn = !customEditorsOn; tree.Refresh(null, true); } EditorGUILayout.Separator(); if (length > 0) { // collapse/expand if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCollapseAll123, "Collapse all components")) { tree.ExpandCollapseAll(true); } EditorGUILayout.Separator(); if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGExpandAll123, "Expand all components")) { tree.ExpandCollapseAll(false); } EditorGUILayout.Separator(); // delete all Ccs if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Delete all components") && BGEditorUtility.Confirm("Delete", "Are you sure you want to delete " + length + " component(s)?", "Delete")) { tree.Delete(); } EditorGUILayout.Separator(); } //add new Cc if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new component")) { BGCcAddWindow.Open(Curve, type => AddComponent(Curve, type)); } }); if (length > 0) { // warnings/errors if (hasWarning || hasError) { for (var i = 0; i < components.Length; i++) { var component = components[i]; var name = (component.Descriptor != null ? component.Descriptor.Name + " " : "") + component.CcName; var error = component.Error; if (!string.IsNullOrEmpty(error)) { BGEditorUtility.HelpBox("Component error [" + name + "]: " + error, MessageType.Error); } var warning = component.Warning; if (!string.IsNullOrEmpty(warning)) { BGEditorUtility.HelpBox("Component warning [" + name + "]: " + warning, MessageType.Warning); } } } else { BGEditorUtility.HelpBox("No warnings or errors", MessageType.Info); } // tree GUI tree.OnInspectorGui(); } else { EditorGUILayout.HelpBox( "Hit the Plus icon to add a component" + "\r\n" + "\r\n" + "Components allows to add functionality without any scripting." , MessageType.Info); } if (hasError ^ HasError || hasWarning ^ HasWarning) { EditorApplication.RepaintHierarchyWindow(); } }
internal void OnInspectorGUI(BGCurvePoint point, int index, BGCurveSettings settings) { var maskField = point.Curve.Mode2DOn && Event.current.type == EventType.Repaint; BGEditorUtility.HorizontalBox(() => { editorSelection.InspectorSelectionRect(point); BGEditorUtility.VerticalBox(() => { BGEditorUtility.SwapLabelWidth(60, () => { if (!settings.ShowPointPosition && !settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { EditorGUILayout.LabelField("Point " + index); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { //control type if (settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { point.ControlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Point " + index, point.ControlType); PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } //position if (settings.ShowPointPosition) { var math = editor.Editor.Math; var positionWorld = math.GetPosition(index); if (!settings.ShowPointControlType) { BGEditorUtility.Horizontal(() => { BGEditorUtility.Vector3Field("Point " + index, "Point's position in world space", positionWorld, vector3 => point.PositionWorld = vector3); if (maskField) { MaskFieldFor2D(point); } PointButtons(point, index, settings); }); BGEditorUtility.StartIndent(1); } else { BGEditorUtility.Vector3Field("Pos", "Point's position in world space", positionWorld, vector3 => point.PositionWorld = vector3); if (maskField) { MaskFieldFor2D(point); } } } } }); // control positions if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent && settings.ShowPointControlPositions) { // 1st BGEditorUtility.Vector3Field("Control 1", "Point 1st control position (local)", point.ControlFirstLocal, vector3 => { point.ControlFirstLocal = vector3; }); if (maskField) { MaskFieldFor2D(point); } // 2nd BGEditorUtility.Vector3Field("Control 2", "Point 2nd control position (local)", point.ControlSecondLocal, vector3 => { point.ControlSecondLocal = vector3; }); if (maskField) { MaskFieldFor2D(point); } } BGEditorUtility.EndIndent(1); }); }); }