Beispiel #1
0
        void OnSceneGUI()
        {
            if (spline != null && !spline.Equals(null))
            {
                Event e = Event.current;
                if (e.type == EventType.ValidateCommand)
                {
                    if (e.commandName == "Delete")
                    {
                        RemovePointAt(spline.IndexOf(point));
                        e.type = EventType.Ignore;

                        return;
                    }
                    else if (e.commandName == "Duplicate")
                    {
                        DuplicatePointAt(spline.IndexOf(point));
                        e.type = EventType.Ignore;
                    }
                }

                if (e.isKey && e.type == EventType.KeyDown && e.keyCode == KeyCode.Delete)
                {
                    RemovePointAt(spline.IndexOf(point));
                    e.Use();

                    return;
                }

                BezierUtils.DrawSplineDetailed(spline);
                for (int i = 0; i < spline.Count; i++)
                {
                    BezierUtils.DrawBezierPoint(spline[i], i + 1, spline[i] == point);
                }
            }
            else
            {
                BezierUtils.DrawBezierPoint(point, 0, true);
            }

            // Draw translate handles for control points
            if (Event.current.alt)
            {
                return;
            }

            if (Tools.current != Tool.Move)
            {
                controlPointRotationsInitialized = false;
                return;
            }

            if (!controlPointRotationsInitialized)
            {
                precedingPointRotation = Quaternion.LookRotation(point.precedingControlPointPosition - point.position);
                followingPointRotation = Quaternion.LookRotation(point.followingControlPointPosition - point.position);

                controlPointRotationsInitialized = true;
            }

            EditorGUI.BeginChangeCheck();
            Vector3 position = Handles.PositionHandle(point.precedingControlPointPosition, Tools.pivotRotation == PivotRotation.Local ? precedingPointRotation : Quaternion.identity);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(point, "Move Control Point");
                point.precedingControlPointPosition = position;
            }

            EditorGUI.BeginChangeCheck();
            position = Handles.PositionHandle(point.followingControlPointPosition, Tools.pivotRotation == PivotRotation.Local ? followingPointRotation : Quaternion.identity);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(point, "Move Control Point");
                point.followingControlPointPosition = position;
            }
        }