Ejemplo n.º 1
0
        public static void ClickPixels(int x, int y)
        {
            GameObject go = UITestUtils.FindObjectByPixels(x, y);

            if (go == null)
            {
                Assert.Fail("Cannot click to pixels [" + x + ";" + y + "], couse there are no objects.");
            }
            Interact.Click(go);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Uses `UnityEngine.EventSystems.EventSystem` class to raycast by given coordinates to find `GameObject` and perform drag on it
        /// </summary>
        /// <param name="from">Start position in pixels</param>
        /// <param name="to">Finish position in pixels</param>
        /// <param name="time">Drag Time (optional, default = 1)</param>
        public static IEnumerator DragPixels(Vector2 from, Vector2 to, float time = 1)
        {
            var go = UITestUtils.FindObjectByPixels(from.x, from.y);

            if (go == null)
            {
                Assert.Fail("Cannot grag object from pixels [" + from.x + ";" + from.y +
                            "], couse there are no objects.");
            }
            yield return(DragPixels(go, from, to, time));
        }
Ejemplo n.º 3
0
        public static GameObject FindUIObjectWhichOverlayGivenObject(GameObject overlayedGameObject)
        {
            var rtr = overlayedGameObject.GetComponent <RectTransform>();

            if (!rtr)
            {
                Debug.LogError("rect transform is null for Gameobject: " +
                               UITestUtils.GetGameObjectFullPath(overlayedGameObject));
            }
            var point = UITestUtils.CenterPointOfObject(rtr);

            GameObject gameObjectUnderClick = UITestUtils.FindObjectByPixels(point.x, point.y);

            if (gameObjectUnderClick == null || gameObjectUnderClick == overlayedGameObject)
            {
                return(null);
            }

            GameObject parent = null;

            if (gameObjectUnderClick.transform.parent)
            {
                parent = gameObjectUnderClick.transform.parent.gameObject;
            }

            while (parent)
            {
                if (parent == overlayedGameObject)
                {
                    return(null);
                }
                if (parent.transform.parent)
                {
                    parent = parent.transform.parent.gameObject;
                }
                else
                {
                    parent = null;
                }
            }

            return(gameObjectUnderClick);
        }
Ejemplo n.º 4
0
        private Dictionary <Assertation, GameObject> FindGameObjectToAssertationByClick(Vector2 pos)
        {
            Dictionary <Assertation, GameObject> result = new Dictionary <Assertation, GameObject>();

            foreach (var assertation in assertations)
            {
                GameObject go     = null;
                var        camera = assertation.Helper.GetCamera();
                if (camera != null)
                {
                    var hit = Physics2D.Raycast(camera.ScreenToWorldPoint(Input.mousePosition),
                                                Vector2.zero);
                    if (hit.collider != null)
                    {
                        go = hit.collider.gameObject;
                    }
                }
                else
                {
                    go = UITestUtils.FindObjectByPixels(pos.x, pos.y, new HashSet <string> {
                        UI_TEST_SCREEN_BLOCKER
                    });
                }

                if (go)
                {
                    var adjustedGo = FindAvailableInParents(go, assertation.Helper);
                    if (adjustedGo)
                    {
                        result[assertation] = adjustedGo;
                    }
                }
            }

            return(result);
        }