Example #1
0
    private void OnSceneGUI()
    {
        if (drawPoints)
        {
            HandleUtility.AddDefaultControl(GetHashCode());

            var pick_new_vert = GrindSplineUtils.PickNearestVertexToCursor(out var pos);

            if (pick_new_vert)
            {
                nearestVert = pos;
            }

            HandleUtility.Repaint();

            Handles.color = Color.green;

            if (grindSpline.transform.childCount > 0)
            {
                Handles.DrawAAPolyLine(3f, grindSpline.transform.GetChild(grindSpline.transform.childCount - 1).position, nearestVert);
            }

            var label = "Shift Click : Add Point\n" +
                        $"Space : Confirm\n" +
                        $"Escape : Cancel";

            var offset = Vector3.up * Mathf.Lerp(0.1f, 1f, Mathf.Clamp01(SceneView.currentDrawingSceneView.cameraDistance / 4));

            Handles.Label(nearestVert + offset, label, new GUIStyle("whiteLabel")
            {
                richText = true, fontSize = 14, fontStyle = FontStyle.Bold
            });
            Handles.CircleHandleCap(0, nearestVert, Quaternion.LookRotation(SceneView.currentDrawingSceneView.camera.transform.forward), 0.02f, EventType.Repaint);

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

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

            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();
            }
        }
    }
Example #2
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Add Point"))
        {
            GrindSplineUtils.AddPoint(grindSpline);
        }

        drawPoints = GUILayout.Toggle(drawPoints, "Draw Points", new GUIStyle("button"));

        if (GUILayout.Button("Rename Points"))
        {
            foreach (Transform x in grindSpline.transform)
            {
                x.gameObject.name = $"Point ({x.GetSiblingIndex() + 1})";
            }
        }
    }
    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();
            }
        }
    }
    public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfRequiredOrScript();

        EditorGUILayout.Space();

        EditorGUI.BeginChangeCheck();

        using (new EditorGUILayout.VerticalScope(new GUIStyle("box")))
        {
            EditorGUILayout.LabelField("Grind Settings", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("SurfaceType"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("IsRound"));

            EditorGUILayout.HelpBox("These are used by the map importer to determine what kind of grind this is", MessageType.Info, true);
        }

        if (targets.Length == 1)
        {
            using (new EditorGUILayout.VerticalScope(new GUIStyle("box")))
            {
                EditorGUILayout.LabelField("Spline Tools", EditorStyles.boldLabel);
                EditorGUILayout.BeginHorizontal();

                if (GUILayout.Button("Add Point"))
                {
                    GrindSplineUtils.AddPoint(grindSpline);
                }

                drawPoints = GUILayout.Toggle(drawPoints, "Draw Points", new GUIStyle("button"));

                EditorGUILayout.EndHorizontal();

                if (GUILayout.Button("Rename Points"))
                {
                    foreach (Transform x in grindSpline.PointsContainer)
                    {
                        x.gameObject.name = $"Point ({x.GetSiblingIndex() + 1})";
                    }
                }

                EditorGUILayout.PropertyField(serializedObject.FindProperty("PointsContainer"));

                EditorGUI.indentLevel++;

                if (grindSpline.PointsContainer != null)
                {
                    showPoints = EditorGUILayout.Foldout(showPoints, $"Points ({grindSpline.PointsContainer.childCount})");
                    if (showPoints)
                    {
                        foreach (Transform child in grindSpline.PointsContainer)
                        {
                            EditorGUILayout.ObjectField(child, typeof(Transform), true);
                        }
                    }
                }
                EditorGUI.indentLevel--;
            }
        }

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }

        using (new EditorGUILayout.VerticalScope(new GUIStyle("box")))
        {
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.LabelField("Colliders ", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ColliderContainer"));
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ColliderGenerationSettings"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedColliders"), true);
            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }

            if (GUILayout.Button("Generate Colliders"))
            {
                if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    foreach (var o in targets)
                    {
                        var t = (GrindSpline)o;

                        t.GenerateColliders();
                    }
                }
            }
        }
    }
Example #5
0
    private void OnSceneGUI()
    {
        if (drawSplines)
        {
            HandleUtility.AddDefaultControl(GetHashCode());

            var pick_new_vert = GrindSplineUtils.PickNearestVertexToCursor(out var pos, 0, grindSurface.transform);

            if (pick_new_vert)
            {
                nearestVert = pos;
            }

            HandleUtility.Repaint();

            Handles.color = Color.green;

            if (activeSpline != null && activeSpline.transform.childCount > 0)
            {
                Handles.DrawAAPolyLine(3f, activeSpline.transform.GetChild(activeSpline.transform.childCount - 1).position, nearestVert);
            }

            var label = (activeSpline != null ? "Shift Click : Add Point\n" : "Shift + LMB : Create Grind\n") +
                        $"Space : Confirm\n" +
                        $"Escape : {(activeSpline == null ? "Exit Drawing Mode" : "Cancel")}";

            var offset = Vector3.up * Mathf.Lerp(0.1f, 1f, Mathf.Clamp01(SceneView.currentDrawingSceneView.cameraDistance / 4));

            Handles.Label(nearestVert + offset, label, new GUIStyle("whiteLabel")
            {
                richText = true, fontSize = 14, fontStyle = FontStyle.Bold
            });
            Handles.CircleHandleCap(0, nearestVert, Quaternion.LookRotation(SceneView.currentDrawingSceneView.camera.transform.forward), 0.02f, EventType.Repaint);

            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.transform.position = nearestVert;

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

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

            if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Space)
            {
                if (activeSpline != null && activeSpline.transform.childCount < 2)
                {
                    DestroyImmediate(activeSpline.gameObject);
                    grindSurface.Splines.Remove(activeSpline);
                }

                activeSpline = null;

                grindSurface.GenerateColliders();

                Repaint();
            }

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

                if (activeSpline != null)
                {
                    DestroyImmediate(activeSpline.gameObject);
                    grindSurface.Splines.Remove(activeSpline);
                    activeSpline = null;
                }

                grindSurface.GenerateColliders();

                Repaint();
            }
        }
    }
Example #6
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();
            }
        }
    }