示例#1
0
            public static IEnumerator SimulateMouseMove(EditorWindow window, Vector2 positionFrom, Vector2 positionTo, MouseButton button = MouseButton.LeftMouse, EventModifiers modifiers = EventModifiers.None)
            {
                const int dragSamples     = 10;
                const int moveFramesDelay = 1;
                var       dragDistance    = Vector2.Distance(positionFrom, positionTo);
                var       dragSpeed       = Mathf.Max(1f, dragDistance / dragSamples);

                var normalizedDirection  = (positionTo - positionFrom).normalized;
                var currentMousePosition = positionFrom;

                do
                {
                    currentMousePosition += dragSpeed * normalizedDirection;
                    var moveEvt = new Event
                    {
                        type          = EventType.MouseMove,
                        mousePosition = currentMousePosition,
                        delta         = normalizedDirection,
                        button        = (int)button,
                        modifiers     = modifiers
                    };

                    window.rootVisualElement.SendEvent(UIETestEvents.MakeEvent(moveEvt));
                    yield return(UIETestHelpers.Pause(moveFramesDelay));
                } while (Vector2.Distance(currentMousePosition, positionTo) > 1f);
            }
示例#2
0
            public static EventBase MakeMouseMoveEvent(Vector2 deltaMove, MouseButton button = MouseButton.LeftMouse, EventModifiers modifiers = EventModifiers.None, int clickCount = 1)
            {
                var evt = new Event {
                    type = EventType.MouseMove, delta = deltaMove, button = (int)button, modifiers = modifiers, clickCount = clickCount
                };

                return(UIETestEvents.MakeEvent(evt));
            }
示例#3
0
            public static EventBase MakeEvent(EventType type, Vector2 position, MouseButton button = MouseButton.LeftMouse, EventModifiers modifiers = EventModifiers.None, int clickCount = 1)
            {
                var evt = new Event {
                    type = type, mousePosition = position, button = (int)button, modifiers = modifiers, clickCount = clickCount
                };

                return(UIETestEvents.MakeEvent(evt));
            }
示例#4
0
            public static EventBase MakeEvent(EventType type, char character, EventModifiers modifiers = EventModifiers.None)
            {
                var evt = new Event {
                    type = type, keyCode = KeyCode.None, character = character, modifiers = modifiers
                };

                return(UIETestEvents.MakeEvent(evt));
            }
示例#5
0
            public static EventBase SimulateScroll(Vector2 delta, Vector2 position)
            {
                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                return(UIETestEvents.MakeEvent(evt));
            }
示例#6
0
            public static IEnumerator SimulateScroll(Vector2 delta, Vector2 position)
            {
                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                UIETestEvents.MakeEvent(evt);
                yield return(UIETestHelpers.Pause());
            }
示例#7
0
            public static IEnumerator SimulateScroll(VisualElement target, Vector2 delta, Vector2 position)
            {
                Assert.That(target.panel, Is.Not.Null);
                var root = UIETestHelpers.GetRoot(target);

                var evt = new Event
                {
                    type          = EventType.ScrollWheel,
                    delta         = delta,
                    mousePosition = position
                };

                var scrollEvent = UIETestEvents.MakeEvent(evt);

                root.SendEvent(scrollEvent);
                yield return(UIETestHelpers.Pause());
            }