Esempio n. 1
0
        static void DoOrientationHandles(ProBuilderShape proBuilderShape, bool updatePrefs)
        {
            if (GUIUtility.hotControl != 0 && !k_OrientationControlIDs.Contains(GUIUtility.hotControl))
            {
                return;
            }

            foreach (var f in faces)
            {
                if (f.IsVisible && EditorShapeUtility.PointerIsInFace(f))
                {
                    if (DoOrientationHandle(f, proBuilderShape))
                    {
                        UndoUtility.RecordComponents <Transform, ProBuilderMesh, ProBuilderShape>(proBuilderShape.GetComponents(typeof(Component)), "Rotate Shape");
                        proBuilderShape.RotateInsideBounds(s_ShapeRotation);

                        ProBuilderEditor.Refresh();

                        if (updatePrefs)
                        {
                            DrawShapeTool.SaveShapeParams(proBuilderShape);
                        }
                    }
                }
            }
        }
Esempio n. 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);
        }