private void PointButtons(BGCurvePointI point, int index, BGCurveSettings settings) { if (!settings.ShowPointMenu) { return; } var curve = point.Curve; //================== Copy if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCopy123, PointCopyPaste.Instance.CopyTooltip)) { PointCopyPaste.Instance.Copy(point); } GUILayout.Space(2); //================== Paste if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGPaste123, PointCopyPaste.Instance.PasteTooltip)) { PointCopyPaste.Instance.Paste(point); } GUILayout.Space(2); //================== Add before if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Insert a point before this point")) { BGCurveEditor.AddPoint(curve, BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index); } GUILayout.Space(2); //=========================== Move Up if (index > 0 && BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGMoveUp123, "Move the point up")) { curve.Swap(index - 1, index); } GUILayout.Space(2); //=========================== Move Down if (index < curve.PointsCount - 1 && BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGMoveDown123, "Move the point down")) { curve.Swap(index, index + 1); } GUILayout.Space(2); //=========================== Delete if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Delete the point")) { BGCurveEditor.DeletePoint(curve, index); if (editorSelection != null) { editorSelection.Remove(point); } GUIUtility.ExitGUI(); } }
protected override void AdditionalMenuItems() { Add(new MenuSeparator()); //add before Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertBefore123), "Insert a point before this point", () => { var curve = point.Curve; var settings = BGPrivateField.GetSettings(curve); var index = curve.IndexOf(point); BGCurveEditor.AddPoint(curve, BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index); })); //add after Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertAfter123), "Insert a point after this point", () => { var curve = point.Curve; var settings = BGPrivateField.GetSettings(curve); var index = curve.IndexOf(point); BGCurveEditor.AddPoint(curve, BGNewPointPositionManager.InsertAfter(curve, index, settings.ControlType, settings.Sections), index + 1); })); //add remove to selection addToSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionAdd123), "Add this point to selection", () => EditorSelection.Add(point)); removeFromSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection", () => EditorSelection.Remove(point)); Add(addToSelectionItem); Add(removeFromSelectionItem); }
// ================================================================================ 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(); }
//see base class for description internal override bool Seize(Event currentEvent, ref Vector3 position, ref string message) { if (!Comply(currentEvent)) { return(false); } Vector3 intersectionPosition; Plane plane; if (currentEvent.type == EventType.mouseDown && currentEvent.control && currentEvent.button == 0) { //Mouse down for some action var curve = overlay.Editor.Curve; var settings = overlay.Editor.Settings; Cast(currentEvent, HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition), out intersectionPosition, out message, out plane); if (message != null) { BGCurveEditor.OverlayMessage.Display(message); } else { position = intersectionPosition; BGCurveEditor.AddPoint(curve, BGNewPointPositionManager.CreatePoint(intersectionPosition, curve, settings.ControlType, settings.Sections, true), curve.PointsCount); } overlay.EventCanceller = new BGEditorUtility.EventCanceller(); return(true); } if (!(currentEvent.type == EventType.Repaint && currentEvent.control || currentEvent.type == EventType.MouseMove && currentEvent.control)) { return(false); } var ray = HandleUtility.GUIPointToWorldRay(currentEvent.mousePosition); Cast(currentEvent, ray, out intersectionPosition, out message, out plane); position = intersectionPosition; if (message != null) { return(true); } Animation(plane, ray, swayTransition); //preview float toLast = -1, toFirst = -1; Preview(intersectionPosition, overlay.Editor.Curve, ref toLast, ref toFirst); //distance message = BGSceneViewOverlay.ToOk("MouseClick to add a point\r\n") + //to last (toLast < 0 ? "First point is ready to go!" : "Distance to last=" + toLast) + //to first (toFirst < 0 ? "" : ", to first=" + toFirst); return(true); }
protected override void AddPoint(BGCurve curve, Vector3 intersectionPosition, BGCurveSettings settings) { BGCurveEditor.AddPoint(curve, CreatePoint(curve, settings), pointIndex + 1); }
//default implementation adds a point to the spline's end protected virtual void AddPoint(BGCurve curve, Vector3 intersectionPosition, BGCurveSettings settings) { BGCurveEditor.AddPoint(curve, BGNewPointPositionManager.CreatePoint(intersectionPosition, curve, settings.ControlType, settings.Sections, true), curve.PointsCount); }