Beispiel #1
0
        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 changed = GUI.changed;

            GUI.changed = false;
            Vector2 vector = Slider2D.CalcDeltaAlongDirections(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, snap, drawHelper);

            if (GUI.changed)
            {
                handlePos = Slider2D.s_StartPosition + slideDir1 * vector.x + slideDir2 * vector.y;
            }
            GUI.changed |= changed;
            return(handlePos);
        }
Beispiel #2
0
 public static Vector3 Do(int id, Vector3 handlePos, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.DrawCapFunction drawFunc, float snap, bool drawHelper)
 {
     return(Slider2D.Do(id, handlePos, new Vector3(0f, 0f, 0f), handleDir, slideDir1, slideDir2, handleSize, drawFunc, new Vector2(snap, snap), drawHelper));
 }
Beispiel #3
0
 public static Vector3 Do(int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.CapFunction capFunction, float snap, bool drawHelper)
 {
     return(Slider2D.Do(id, handlePos, offset, handleDir, slideDir1, slideDir2, handleSize, capFunction, new Vector2(snap, snap), drawHelper));
 }
Beispiel #4
0
        private static Vector2 CalcDeltaAlongDirections(int id, Vector3 handlePos, Vector3 offset, Vector3 handleDir, Vector3 slideDir1, Vector3 slideDir2, float handleSize, Handles.CapFunction capFunction, Vector2 snap, bool drawHelper)
        {
            Vector3    vector   = handlePos + offset;
            Quaternion rotation = Quaternion.LookRotation(handleDir, slideDir1);
            Vector2    vector2  = new Vector2(0f, 0f);
            Event      current  = Event.current;

            switch (current.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (((HandleUtility.nearestControl == id && current.button == 0) || (GUIUtility.keyboardControl == id && current.button == 2)) && GUIUtility.hotControl == 0)
                {
                    bool    flag = true;
                    Vector3 a    = Handles.inverseMatrix.MultiplyPoint(Slider2D.GetMousePosition(handleDir, handlePos, ref flag));
                    if (flag)
                    {
                        GUIUtility.keyboardControl      = id;
                        GUIUtility.hotControl           = id;
                        Slider2D.s_CurrentMousePosition = current.mousePosition;
                        Slider2D.s_StartPosition        = handlePos;
                        Vector3 lhs = a - handlePos;
                        Slider2D.s_StartPlaneOffset.x = Vector3.Dot(lhs, slideDir1);
                        Slider2D.s_StartPlaneOffset.y = Vector3.Dot(lhs, slideDir2);
                        current.Use();
                        EditorGUIUtility.SetWantsMouseJumping(1);
                    }
                }
                break;

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

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Slider2D.s_CurrentMousePosition += current.delta;
                    bool    flag2 = true;
                    Vector3 point = Handles.inverseMatrix.MultiplyPoint(Slider2D.GetMousePosition(handleDir, handlePos, ref flag2));
                    if (flag2)
                    {
                        vector2.x = HandleUtility.PointOnLineParameter(point, Slider2D.s_StartPosition, slideDir1);
                        vector2.y = HandleUtility.PointOnLineParameter(point, Slider2D.s_StartPosition, slideDir2);
                        vector2  -= Slider2D.s_StartPlaneOffset;
                        if (snap.x > 0f || snap.y > 0f)
                        {
                            vector2.x = Handles.SnapValue(vector2.x, snap.x);
                            vector2.y = Handles.SnapValue(vector2.y, snap.y);
                        }
                        GUI.changed = true;
                    }
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (capFunction != null)
                {
                    Color color = Color.white;
                    if (id == GUIUtility.keyboardControl)
                    {
                        color         = Handles.color;
                        Handles.color = Handles.selectedColor;
                    }
                    capFunction(id, vector, rotation, handleSize, EventType.Repaint);
                    if (id == GUIUtility.keyboardControl)
                    {
                        Handles.color = color;
                    }
                    if (drawHelper && GUIUtility.hotControl == id)
                    {
                        Vector3[] array = new Vector3[4];
                        float     d     = handleSize * 10f;
                        array[0] = vector + (slideDir1 * d + slideDir2 * d);
                        array[1] = array[0] - slideDir1 * d * 2f;
                        array[2] = array[1] - slideDir2 * d * 2f;
                        array[3] = array[2] + slideDir1 * d * 2f;
                        Color color2 = Handles.color;
                        Handles.color = Color.white;
                        float num = 0.6f;
                        Handles.DrawSolidRectangleWithOutline(array, new Color(1f, 1f, 1f, 0.05f), new Color(num, num, num, 0.4f));
                        Handles.color = color2;
                    }
                }
                break;

            case EventType.Layout:
                if (capFunction != null)
                {
                    capFunction(id, vector, rotation, handleSize, EventType.Layout);
                }
                else
                {
                    HandleUtility.AddControl(id, HandleUtility.DistanceToCircle(handlePos + offset, handleSize * 0.5f));
                }
                break;
            }
            return(vector2);
        }