// preview
        protected void Preview(Vector3 position, BGCurve curve, ref float toLast, ref float toFirst)
        {
            var settings = overlay.Editor.Settings;

            //show point
            BGEditorUtility.SwapHandlesColor(settings.SphereColor, () => Handles.SphereCap(0, position, Quaternion.identity, BGEditorUtility.GetHandleSize(position, ScalePreviewPoint)));

            //create a point
            var newPoint = BGNewPointPositionManager.CreatePoint(position, curve, settings.ControlType, settings.Sections, out toLast, out toFirst, false);

            //show controls
            if (newPoint.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
            {
                PreviewControls(settings, position, newPoint.ControlFirstWorld, newPoint.ControlSecondWorld);
            }

            if (curve.PointsCount == 0)
            {
                return;
            }

            BGEditorUtility.SwapHandlesColor(BGCurveSettingsForEditor.ColorForNewSectionPreview, () =>
            {
                // last To new
                DrawSection(curve[curve.PointsCount - 1], newPoint, settings.Sections);

                AdditionalPreview(newPoint);

                // new To zero
                if (curve.Closed)
                {
                    DrawSection(newPoint, curve[0], settings.Sections);
                }
            });
        }
Exemplo n.º 2
0
            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);
                    curve.AddPoint(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);
                    curve.AddPoint(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);
            }
        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();
            }
        }
        private BGCurvePoint CreatePoint(BGCurve curve, BGCurveSettings settings)
        {
            var math = overlay.Editor.Editor.Math;

            var from    = curve[pointIndex];
            var to      = pointIndex == curve.PointsCount - 1 ? curve[0] : curve[pointIndex + 1];
            var ratio   = (splineIntersectionDistance - math[pointIndex].DistanceFromStartToOrigin) / math[pointIndex].Distance;
            var tangent = BGEditorUtility.CalculateTangent(@from, to, ratio);

            var point = BGNewPointPositionManager.CreatePointBetween(curve, @from, to, settings.Sections, settings.ControlType, intersectPosition, tangent);

            return(point);
        }
Exemplo n.º 5
0
        private void PointButtons(BGCurvePoint point, int index, BGCurveSettings settings)
        {
            if (!settings.ShowPointMenu)
            {
                return;
            }

            var curve = point.Curve;

            //================== Add before
            if (BGEditorUtility.ButtonWithIcon(addBeforeTexture, "Insert a point before this point"))
            {
                curve.AddPoint(BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index);
            }

            GUILayout.Space(2);


            //=========================== Move Up
            if (index > 0 && BGEditorUtility.ButtonWithIcon(moveUpTexture, "Move the point up"))
            {
                curve.Swap(index - 1, index);
            }
            GUILayout.Space(2);

            //=========================== Move Down
            if (index < curve.PointsCount - 1 && BGEditorUtility.ButtonWithIcon(moveDownTexture, "Move the point down"))
            {
                curve.Swap(index, index + 1);
            }
            GUILayout.Space(2);


            //=========================== Delete
            if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete the point"))
            {
                curve.Delete(index);
                editorSelection.Remove(point);
                GUIUtility.ExitGUI();
            }
        }
        //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);
        }
 //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);
 }
 protected virtual BGCurvePoint CreatePointForPreview(Vector3 position, BGCurve curve, out float toLast, out float toFirst, BGCurveSettings settings)
 {
     return(BGNewPointPositionManager.CreatePoint(position, curve, settings.ControlType, settings.Sections, out toLast, out toFirst, false));
 }