Esempio n. 1
0
#pragma warning disable 618
        public static Vector3 Do(
            int id,
            Vector3 handlePos,
            Vector3 offset,
            Vector3 handleDir,
            Vector3 slideDir1,
            Vector3 slideDir2,
            float handleSize,
            Handles.DrawCapFunction drawFunc,
            Vector2 snap,
            bool drawHelper)
#pragma warning restore 618
        {
            bool orgGuiChanged = GUI.changed;

            GUI.changed = false;

            Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, drawFunc, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y;

                if (EditorSnapSettings.gridSnapActive)
                {
                    var normal = Vector3.Cross(slideDir1, slideDir2);

                    if (Snapping.IsCardinalDirection(normal))
                    {
                        var worldSpace = Handles.matrix.MultiplyPoint(handlePos);
                        worldSpace = Snapping.Snap(worldSpace, GridSettings.size, (SnapAxis) ~new SnapAxisFilter(normal));
                        handlePos  = Handles.inverseMatrix.MultiplyPoint(worldSpace);
                    }
                }
            }

            GUI.changed |= orgGuiChanged;
            return(handlePos);
        }
Esempio n. 2
0
        // Returns the new handlePos
        public static Vector3 Do(
            int id,
            Vector3 handlePos,
            Vector3 offset,
            Vector3 handleDir,
            Vector3 slideDir1,
            Vector3 slideDir2,
            float handleSize,
            Handles.CapFunction capFunction,
            Vector2 snap,
            bool drawHelper)
        {
            bool orgGuiChanged = GUI.changed;

            GUI.changed = false;

            Vector2 delta = CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = s_StartPosition + slideDir1 * delta.x + slideDir2 * delta.y;

                if (EditorSnapSettings.active && EditorSnapSettings.preferGrid)
                {
                    var normal = Vector3.Cross(slideDir1, slideDir2);

                    if (Snapping.IsCardinalDirection(normal))
                    {
                        var worldSpace = Handles.matrix.MultiplyPoint(handlePos);
                        worldSpace = Handles.SnapValue(worldSpace, (~new SnapAxisFilter(normal)) * snap);
                        handlePos  = Handles.inverseMatrix.MultiplyPoint(worldSpace);
                    }
                }
            }

            GUI.changed |= orgGuiChanged;
            return(handlePos);
        }
Esempio n. 3
0
        internal static Vector3 Do(int id, Vector3 position, Vector3 offset, Vector3 handleDirection, Vector3 slideDirection, float size, Handles.CapFunction capFunction, float snap)
        {
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
                if (capFunction != null)
                {
                    capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Layout);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(position + offset, size * .2f));
                }
                break;

            case EventType.MouseDown:
                // am I closest to the thingy?
                if (HandleUtility.nearestControl == id && evt.button == 0 && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    GUIUtility.hotControl  = id;       // Grab mouse focus
                    s_CurrentMousePosition = s_StartMousePosition = evt.mousePosition;
                    s_StartPosition        = position;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(1);
                }

                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    s_CurrentMousePosition += evt.delta;
                    float dist = HandleUtility.CalcLineTranslation(s_StartMousePosition, s_CurrentMousePosition, s_StartPosition, slideDirection);

                    dist = Handles.SnapValue(dist, snap);

                    Vector3 worldDirection = Handles.matrix.MultiplyVector(slideDirection);
                    Vector3 worldPosition  = Handles.matrix.MultiplyPoint(s_StartPosition) + worldDirection * dist;

                    if (EditorSnapSettings.active && EditorSnapSettings.preferGrid && Snapping.IsCardinalDirection(worldDirection))
                    {
                        worldPosition = Handles.SnapValue(worldPosition, new SnapAxisFilter(worldDirection) * snap);
                    }

                    position = Handles.inverseMatrix.MultiplyPoint(worldPosition);

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && (evt.button == 0 || evt.button == 2))
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                    EditorGUIUtility.SetWantsMouseJumping(0);
                }
                break;

            case EventType.MouseMove:
                if (id == HandleUtility.nearestControl)
                {
                    HandleUtility.Repaint();
                }
                break;

            case EventType.Repaint:
                Color temp = Color.white;

                if (id == GUIUtility.hotControl)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.selectedColor;
                }
                else if (id == HandleUtility.nearestControl && GUIUtility.hotControl == 0 && !evt.alt)
                {
                    temp          = Handles.color;
                    Handles.color = Handles.preselectionColor;
                }

                capFunction(id, position + offset, Quaternion.LookRotation(handleDirection), size, EventType.Repaint);

                if (id == GUIUtility.hotControl || id == HandleUtility.nearestControl && GUIUtility.hotControl == 0)
                {
                    Handles.color = temp;
                }
                break;
            }
            return(position);
        }