static bool DoFaceSizeHandle(FaceData face)
        {
            float handleSize = HandleUtility.GetHandleSize(face.CenterPosition) * s_DefaultMidpointHandleSize;

            var snap = Vector3.Scale(EditorSnapping.incrementalSnapMoveValue, face.Normal).magnitude;

            EditorGUI.BeginChangeCheck();

            Color color = k_BoundsHandleColor;

            color.a *= face.IsVisible ? 1f : 0.25f;
            using (new Handles.DrawingScope(color))
                s_TargetSize = Handles.Slider(face.CenterPosition, face.Normal, handleSize, Handles.DotHandleCap, snap);

            if (EditorGUI.EndChangeCheck())
            {
                return(true);
            }

            if (GUIUtility.hotControl == 0)
            {
                s_SizeManipulationInit = false;
            }

            return(false);
        }
Beispiel #2
0
        static bool DoFaceSizeHandle(FaceData face, int controlID)
        {
            if (k_OrientationControlIDs.Contains(HandleUtility.nearestControl) && !EditorShapeUtility.PointerIsInFace(face))
            {
                return(false);
            }

            Event evt        = Event.current;
            float handleSize = HandleUtility.GetHandleSize(face.CenterPosition) * s_DefaultMidpointHandleSize;
            bool  isSelected = (HandleUtility.nearestControl == controlID && s_CurrentId == -1) || s_CurrentId == controlID;

            switch (evt.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == controlID && evt.button == 0)
                {
                    s_CurrentId            = controlID;
                    GUIUtility.hotControl  = controlID;
                    s_StartMousePosition   = evt.mousePosition;
                    s_SizeManipulationInit = false;
                    evt.Use();
                    SceneView.RepaintAll();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    s_CurrentId            = -1;
                    s_SizeManipulationInit = false;
                }
                break;

            case EventType.Layout:
                HandleUtility.AddControl(controlID, HandleUtility.DistanceToLine(face.CenterPosition, face.CenterPosition) / 2f);
                break;

            case EventType.Repaint:
                Color color = isSelected ? EditorHandleDrawing.edgeSelectedColor : k_BoundsHandleColor;
                color.a *= face.IsVisible ? 1f : 0.25f;
                using (new Handles.DrawingScope(color))
                    Handles.DotHandleCap(controlID, face.CenterPosition, Quaternion.identity, handleSize, EventType.Repaint);
                break;

            case EventType.MouseDrag:
                if (s_CurrentId == controlID)
                {
                    s_SizeDelta = HandleUtility.CalcLineTranslation(s_StartMousePosition, evt.mousePosition, s_StartPositionLocal, face.Normal);
                    return(true);
                }
                break;
            }
            return(false);
        }
Beispiel #3
0
        static bool DoOrientationHandle(FaceData face, ProBuilderShape proBuilderShape)
        {
            Event evt        = Event.current;
            bool  hasRotated = false;

            switch (evt.type)
            {
            case EventType.MouseDown:
                if (k_OrientationControlIDs.Contains(HandleUtility.nearestControl) && evt.button == 0)
                {
                    s_CurrentId           = HandleUtility.nearestControl;
                    GUIUtility.hotControl = s_CurrentId;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (k_OrientationControlIDs.Contains(HandleUtility.nearestControl) && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    if (s_CurrentId == HandleUtility.nearestControl)
                    {
                        //Execute rotation
                        Vector3 targetedNormal = Vector3.zero;
                        for (int i = 0; i < k_OrientationControlIDs.Length; i++)
                        {
                            if (k_OrientationControlIDs[i] == s_CurrentId)
                            {
                                targetedNormal = (s_ArrowsLines[i][1] - face.CenterPosition).normalized;
                                break;
                            }
                        }

                        var currentNormal = face.Normal;
                        currentNormal.Scale(Math.Sign(proBuilderShape.size));
                        targetedNormal.Scale(Math.Sign(proBuilderShape.size));
                        Vector3 rotationAxis = Vector3.Cross(currentNormal, targetedNormal);
                        var     angle        = Vector3.SignedAngle(currentNormal, targetedNormal, rotationAxis);
                        s_ShapeRotation = Quaternion.AngleAxis(angle, rotationAxis);
                        s_CurrentAngle  = (s_CurrentAngle + angle) % 360;

                        hasRotated = true;
                    }
                    s_CurrentId = -1;
                }
                break;

            case EventType.Layout:
                for (int i = 0; i < 4; i++)
                {
                    var   rectPos = 0.8f * s_ArrowsLines[i][1] + 0.2f * face.CenterPosition;
                    float dist    = HandleUtility.DistanceToRectangle(rectPos,
                                                                      Quaternion.LookRotation(face.Normal),
                                                                      HandleUtility.GetHandleSize(face.CenterPosition) * s_DefaultMidpointSquareSize / 2f);
                    HandleUtility.AddControl(k_OrientationControlIDs[i], dist);
                }
                break;

            case EventType.Repaint:
                if (s_CurrentArrowHovered != HandleUtility.nearestControl)
                {
                    s_CurrentAngle = 0f;
                }

                int pointsCount = face.Points.Length;
                s_CurrentArrowHovered = -1;
                for (int i = 0; i < pointsCount; i++)
                {
                    var rectHandleSize = HandleUtility.GetHandleSize(face.CenterPosition) * s_DefaultMidpointSquareSize;

                    var sideDirection  = (face.Points[(i + 1) % pointsCount] - face.Points[i]).normalized;
                    var arrowDirection = Vector3.Cross(face.Normal.normalized, sideDirection).normalized;

                    var topDirection = 2.5f * rectHandleSize * arrowDirection;
                    var top          = face.CenterPosition + topDirection;
                    var A            = topDirection.magnitude;
                    var a            = 0.33f * Mathf.Sqrt(2f * A * A);
                    var h            = 0.5f * Mathf.Sqrt(2f * a * a);
                    s_ArrowsLines[i][0] = top - (h * arrowDirection + h * sideDirection);
                    s_ArrowsLines[i][1] = top;
                    s_ArrowsLines[i][2] = top - (h * arrowDirection - h * sideDirection);

                    bool selected = HandleUtility.nearestControl == k_OrientationControlIDs[i];

                    Color color = selected
                               ? EditorHandleDrawing.edgeSelectedColor
                               : k_BoundsHandleColor;
                    color.a = 1.0f;

                    using (new Handles.DrawingScope(color))
                    {
                        Handles.DrawAAPolyLine(5f, s_ArrowsLines[i]);
                        if (selected)
                        {
                            EditorGUIUtility.AddCursorRect(new Rect(0, 0, Screen.width, Screen.height), MouseCursor.RotateArrow);
                            s_CurrentArrowHovered = HandleUtility.nearestControl;
                            Handles.DrawAAPolyLine(3f,
                                                   new Vector3[]
                            {
                                Vector3.Scale(proBuilderShape.rotation * Vector3.up, proBuilderShape.size / 2f),
                                Vector3.zero,
                                Vector3.Scale(proBuilderShape.rotation * Vector3.forward, proBuilderShape.size / 2f)
                            });
                        }
                    }
                }
                break;

            case EventType.MouseDrag:
                if (k_OrientationControlIDs.Contains(s_CurrentId) && HandleUtility.nearestControl != s_CurrentId)
                {
                    GUIUtility.hotControl = 0;
                    s_CurrentId           = -1;
                }
                break;
            }
            return(hasRotated);
        }