public void Off()
        {
            if (!IsOn)
            {
                return;
            }
            IsOn = false;

            if (selectionWasMade)
            {
                return;
            }

            if (selection.HasSelected())
            {
                selection.Clear();
                SceneView.RepaintAll();
            }
        }
Exemplo n.º 2
0
        public void Off()
        {
            if (!IsOn)
            {
                return;
            }
            IsOn = false;

            if (selectionWasMade)
            {
                return;
            }

            if (selection.HasSelected())
            {
                selection.Clear();
                EditorUtility.SetDirty(curve);
            }
            else
            {
                BGCurveEditor.OverlayMessage.Display("The Scene view is locked.\r\n Set 'Lock View' (in the BGCurve Editor) to false to unlock.");
            }
        }
Exemplo n.º 3
0
        // ================================================================================ 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();
        }
Exemplo n.º 4
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;
                }
            }
        }