Пример #1
0
        static public Transform GetContainerUnderMouse(Vector3 mouse_abs_pos, GameObject ignore_obj = null)
        {
            GameObject           testUI = UIEditorHelper.GetUITestRootNode();
            List <RectTransform> list   = new List <RectTransform>();

            Canvas[]  containers = Transform.FindObjectsOfType <Canvas>();
            Vector3[] corners    = new Vector3[4];
            foreach (var item in containers)
            {
                if (ignore_obj == item.gameObject || item.transform.parent != testUI.transform)
                {
                    continue;
                }
                RectTransform trans = item.transform as RectTransform;
                if (trans != null)
                {
                    //获取节点的四个角的世界坐标,分别按顺序为左下左上,右上右下
                    trans.GetWorldCorners(corners);
                    if (mouse_abs_pos.x >= corners[0].x && mouse_abs_pos.y <= corners[1].y && mouse_abs_pos.x <= corners[2].x && mouse_abs_pos.y >= corners[3].y)
                    {
                        list.Add(trans);
                    }
                }
            }
            if (list.Count <= 0)
            {
                return(null);
            }
            list.Sort((RectTransform a, RectTransform b) => { return((a.GetSiblingIndex() == b.GetSiblingIndex()) ? 0 : ((a.GetSiblingIndex() < b.GetSiblingIndex()) ? 1 : -1)); }
                      );
            return(GetRootLayout(list[0]));
        }
Пример #2
0
        public static GameObject CreatNewLayout(bool isNeedLayout = true)
        {
            GameObject testUI = UIEditorHelper.GetUITestRootNode();

            string file_path = Path.Combine(Configure.ResAssetsPath, "Canvas.prefab");

            file_path = FileUtil.GetProjectRelativePath(file_path);
            GameObject layout_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(file_path, typeof(UnityEngine.Object)) as GameObject;
            GameObject layout        = GameObject.Instantiate(layout_prefab) as GameObject;

            layout.transform.SetParent(testUI.transform);
            Vector3 last_pos = layout.transform.localPosition;

            layout.transform.localPosition = new Vector3(last_pos.x, last_pos.y, 0);
            if (!isNeedLayout)
            {
                Transform child = layout.transform.Find("Layout");
                // layout.transform.DetachChildren();
                if (child != null)
                {
                    Undo.DestroyObjectImmediate(child.gameObject);
                }
            }

            Selection.activeGameObject = layout;
            RectTransform trans = layout.transform as RectTransform;

            SceneView.lastActiveSceneView.MoveToView(trans);
            return(layout);
        }
Пример #3
0
        private static GameObject GetLoadedLayout(string layoutPath)
        {
            GameObject testUI = UIEditorHelper.GetUITestRootNode();

            if (testUI != null)
            {
                LayoutInfo[] layoutInfos = testUI.GetComponentsInChildren <LayoutInfo>(true);
                foreach (var item in layoutInfos)
                {
                    if (item.LayoutPath == layoutPath)
                    {
                        return(item.gameObject);
                    }
                }
            }
            return(null);
        }
Пример #4
0
        public static GameObject CreatNewLayout(bool isNeedLayout = true)
        {
            GameObject   testUI        = UIEditorHelper.GetUITestRootNode();
            const string file_path     = Configure.ResAssetsPath + "Canvas.prefab";
            GameObject   layout_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(file_path, typeof(UnityEngine.Object)) as GameObject;
            GameObject   layout        = GameObject.Instantiate(layout_prefab) as GameObject;

            layout.transform.SetParent(testUI.transform);
            if (!isNeedLayout)
            {
                Transform child = layout.transform.GetChild(0);
                layout.transform.DetachChildren();
                Undo.DestroyObjectImmediate(child.gameObject);
            }

            Selection.activeGameObject = layout;
            RectTransform trans = layout.transform as RectTransform;

            SceneView.lastActiveSceneView.MoveToView(trans);
            return(layout);
        }