コード例 #1
0
        /// <summary>
        /// 判断控件是否当前被触摸到
        /// </summary>
        /// <param name="widget"></param>
        /// <returns></returns>
        public bool IsWidgetTouched(GameObject widget)
        {
            if (widget == null)
            {
                return(false);
            }

            bool          widget_is_visible = false;
            RectTransform rect_trans        = widget.GetComponent <RectTransform>();

            if (rect_trans != null)
            {
                Camera current_cam = UIMainCtrl.MainCam;
                if (current_cam != null)
                {
                    var screen_pos = Input.mousePosition;

                    if (pointerData == null)
                    {
                        pointerData = new PointerEventData(EventSystem.current);
                    }

                    var hit_obj = UGUIMath.GetRaycastObj(screen_pos, pointerData);
                    if (hit_obj != null && UGUIMath.ContainWidget(widget, hit_obj))
                    {
                        widget_is_visible = true;
                    }
                }
            }

            return(widget.activeInHierarchy && widget_is_visible);
        }
コード例 #2
0
        /// <summary>
        /// 判断控件是否可见
        /// </summary>
        /// <param name="widget"></param>
        /// <returns></returns>
        public bool IsWidgetVisible(GameObject widget)
        {
            if (widget == null)
            {
                return(false);
            }

            bool          widget_is_visible = false;
            RectTransform rect_trans        = widget.GetComponent <RectTransform>();

            if (rect_trans != null)
            {
                Vector3[] world_corner = new Vector3[4];
                rect_trans.GetWorldCorners(world_corner);
                Camera current_cam = UIMainCtrl.MainCam;
                if (current_cam != null)
                {
                    Vector3 center     = (world_corner[0] + world_corner[2]) * 0.5f;
                    var     screen_pos = current_cam.WorldToScreenPoint(center);

                    if (pointerData == null)
                    {
                        pointerData = new PointerEventData(EventSystem.current);
                    }

                    bool hasGuideWindow = false;
                    for (int i = m_IgnoreRaycastGameObjects.Count - 1; i >= 0; i--)
                    {
                        if (m_IgnoreRaycastGameObjects[i] == null)
                        {
                            m_IgnoreRaycastGameObjects.Remove(m_IgnoreRaycastGameObjects[i]);
                            continue;
                        }
                        if (m_IgnoreRaycastGameObjects[i].name == "UIGuideWindow")
                        {
                            hasGuideWindow = true;
                            break;
                        }
                    }
                    if (!hasGuideWindow)
                    {
                        UIBaseWindow guidewnd = UIManager.Instance.GetWindow("UIGuideWindow");
                        if (guidewnd != null)
                        {
                            m_IgnoreRaycastGameObjects.Add(guidewnd.mUIObject);
                        }
                    }

                    var hit_obj = UGUIMath.GetRaycastObj(screen_pos, pointerData, m_IgnoreRaycastGameObjects, true);
                    if (hit_obj != null && UGUIMath.ContainWidget(widget, hit_obj))
                    {
                        widget_is_visible = true;
                    }
                }
            }

            return(widget.activeInHierarchy && widget_is_visible);
        }
コード例 #3
0
ファイル: XComponent.cs プロジェクト: wuhuolong/MaxBooks
 /// <summary>
 /// 获取屏幕位置处碰撞到的UI物体
 /// </summary>
 public GameObject GetRaycastObj(Vector3 inPos, UnityEngine.EventSystems.PointerEventData eventDataCurrentPosition, List <GameObject> excludeGameObjects)
 {
     return(UGUIMath.GetRaycastObj(inPos, eventDataCurrentPosition, excludeGameObjects));
 }