private void OnSceneGUI()
    {
        grindSpline.DrawingActive = drawPoints;

        if (drawPoints)
        {
            Tools.current = Tool.None;

            SplineDrawingShared.OnSceneGUI_SplineDrawingCommon(
                editor: this,
                grindSpline: grindSpline,
                lmbLabel: "Shift Click : Add Point",
                vertexSnap: ref vertexSnap,
                pointPosition: ref pointPosition);

            if (Event.current == null)
            {
                return;
            }

            if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && Event.current.modifiers.HasFlag(EventModifiers.Shift))
            {
                GrindSplineUtils.AddPoint(grindSpline, pointPosition);
            }

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Space)
            {
                drawPoints = false;
                Repaint();
            }

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                drawPoints = false;
                Repaint();
            }
        }
    }
Exemple #2
0
    private void OnSceneGUI()
    {
        if (drawSplines)
        {
            Tools.current = Tool.None;

            SplineDrawingShared.OnSceneGUI_SplineDrawingCommon(
                editor: this,
                grindSpline: activeSpline,
                lmbLabel: (activeSpline != null ? "Shift Click : Add Point" : "Shift + LMB : Create Grind"),
                vertexSnap: ref vertexSnap,
                pointPosition: ref pointPosition);

            if (Event.current == null)
            {
                return;
            }

            if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && Event.current.modifiers.HasFlag(EventModifiers.Shift))
            {
                if (activeSpline == null)
                {
                    activeSpline = CreateSpline();
                    activeSpline.DrawingActive      = true;
                    activeSpline.transform.position = pointPosition;

                    Undo.RegisterCreatedObjectUndo(activeSpline.gameObject, "Create GrindSpline");

                    GrindSplineUtils.AddPoint(activeSpline);
                }
                else
                {
                    GrindSplineUtils.AddPoint(activeSpline, pointPosition);
                }
            }

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Space)
            {
                // destroy if invalid

                if (activeSpline != null && activeSpline.PointsContainer.childCount < 2)
                {
                    foreach (var c in activeSpline.GeneratedColliders)
                    {
                        DestroyImmediate(c.gameObject);
                    }

                    DestroyImmediate(activeSpline.gameObject);

                    grindSurface.Splines.Remove(activeSpline);
                }

                activeSpline = null;

                Repaint();
            }

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                drawSplines = false;

                if (activeSpline != null)
                {
                    foreach (var c in activeSpline.GeneratedColliders)
                    {
                        DestroyImmediate(c.gameObject);
                    }

                    DestroyImmediate(activeSpline.gameObject);
                    grindSurface.Splines.Remove(activeSpline);
                    activeSpline.DrawingActive = false;
                    activeSpline = null;
                }

                Repaint();
            }
        }
    }