// OnSceneGui
        public void Scene(Quaternion rotation)
        {
            if (lastCurveCount != curve.PointsCount)
            {
                lastCurveCount = curve.PointsCount;
                OnUndoRedo();
            }

            if (!HasSelected())
            {
                return;
            }

            BGEditorUtility.Assign(ref settings, () => editor.Settings);

            //group operation for selected points
            var text    = " Selected points [" + points.Count + "]";
            var average = GetAveragePosition();

            Handles.Label(editor.GetLabelPosition(settings, average), text, new GUIStyle("Label")
            {
                normal = new GUIStyleState {
                    textColor = settings.LabelColorSelected
                }
            });

            var newAverage = editor.Handle(-10, settings.HandlesType, average, rotation, settings.HandlesSettings);

            if (BGEditorUtility.AnyChange(average, newAverage))
            {
                curve.Transaction(() =>
                {
                    var delta = newAverage - average;
                    foreach (var selectedPoint in points)
                    {
                        selectedPoint.PositionWorld += delta;
                    }
                });
            }
        }
Example #2
0
        public void OnSceneGUI(BGCurvePoint point, int index, BGCurveSettings settings, Quaternion rotation, Plane[] frustum)
        {
            var math          = editor.Editor.Math;
            var positionWorld = math.GetPosition(index);

            if (settings.ShowControlHandles && settings.ShowCurve && (!editorSelection.HasSelected() || editorSelection.SingleSelected(point)))
            {
                // ============================================== Controls Handles
                if (point.ControlType != BGCurvePoint.ControlTypeEnum.Absent)
                {
                    var controlFirstWorld  = math.GetControlFirst(index);
                    var controlSecondWorld = math.GetControlSecond(index);

                    BGEditorUtility.SwapHandlesColor(settings.ControlHandlesColor, () =>
                    {
                        Handles.DrawLine(positionWorld, controlFirstWorld);
                        Handles.DrawLine(positionWorld, controlSecondWorld);

                        // control handles different types
                        var newPositionFirst  = editor.Handle(GetUniqueNumber(index) - 1, settings.ControlHandlesType, controlFirstWorld, rotation, settings.ControlHandlesSettings);
                        var newPositionSecond = editor.Handle(GetUniqueNumber(index) - 2, settings.ControlHandlesType, controlSecondWorld, rotation, settings.ControlHandlesSettings);

                        if (BGEditorUtility.AnyChange(controlFirstWorld, newPositionFirst))
                        {
                            point.ControlFirstWorld = newPositionFirst;
                        }
                        if (BGEditorUtility.AnyChange(controlSecondWorld, newPositionSecond))
                        {
                            point.ControlSecondWorld = newPositionSecond;
                        }
                    });

                    if (settings.ShowControlLabels)
                    {
                        ShowControlLabel(settings, frustum, controlFirstWorld, point.ControlFirstLocal, "1");
                        ShowControlLabel(settings, frustum, controlSecondWorld, point.ControlSecondLocal, "2");
                    }
                }
            }

            //if only one point is selected and this is the selected point- do not print anything further
            if (editorSelection.HasSelected() && editorSelection.SingleSelected(point))
            {
                return;
            }

            // ============================================== Labels & Positions
            if (settings.ShowLabels && GeometryUtility.TestPlanesAABB(frustum, new Bounds(positionWorld, Vector3.one)))
            {
                Handles.Label(editor.GetLabelPosition(settings, positionWorld), "Point " + index + (settings.ShowPositions ? " " + positionWorld : ""),
                              editorSelection.Contains(point) ? selectedPositionLabelStyle : positionLabelStyle);
            }

            // ============================================== Move Handles
            if (!editorSelection.HasSelected() && settings.ShowCurve && settings.ShowHandles)
            {
                var newPos = editor.Handle(GetUniqueNumber(index), settings.HandlesType, positionWorld, rotation, settings.HandlesSettings);

                if (BGEditorUtility.AnyChange(positionWorld, newPos))
                {
                    point.PositionWorld = newPos;
                }
            }
        }