Example #1
0
        /// <summary>
        /// 判断是否在区域内
        /// </summary>
        /// <param name="handIndex"></param>
        /// <returns></returns>
        private bool IsAreaContains(int handIndex)
        {
            if (panelType == PanelType.UI)
            {
                return(MUtility.IsAreaContains(transform, handIndex) || OtherRectAreaContains(handIndex));
            }
            else
            {
                Vector3 screenPoint = MUtility.UIWorldToScreenPoint(transform.position);

                return(MUtility.IsAreaContains(screenPoint, panelSize, handIndex) || OtherRectAreaContains(handIndex));
            }
        }
        void OnButtonRelease(int handIndex)
        {
            if (!enabled)
            {
                return;
            }

            //如果当前手的值不等于-1,并且释放时,跟当前手不符,则直接跳过
            if (this.handIndex != -1 && this.handIndex != handIndex)
            {
                return;
            }

            handIndex = -1;

            GameObject    panelObject   = new GameObject("panel");
            RectTransform rectTransform = panelObject.AddComponent <RectTransform>();

            rectTransform.SetParent(transform);
            rectTransform.localScale    = Vector3.one;
            rectTransform.localPosition = Vector3.zero;

            var parentRect = GetComponent <RectTransform>();

            var templateRect = Template.GetComponent <RectTransform>();

            rectTransform.sizeDelta = new Vector2(parentRect.sizeDelta.x, parentRect.sizeDelta.y + templateRect.sizeDelta.y);

            rectTransform.localPosition = new Vector3(0, -(rectTransform.sizeDelta.y / 2 - parentRect.sizeDelta.y / 2), 0);

            if (!MUtility.IsAreaContains(rectTransform, handIndex))
            {
                Template.SetActive(false);
            }

            DestroyImmediate(panelObject);
        }
Example #3
0
        /// <summary>
        /// 判断其他集合区域是否在范围内
        /// </summary>
        /// <returns></returns>
        private bool OtherRectAreaContains(int hand)
        {
            if (panelType == PanelType.UI)
            {
                if (OtherRects == null)
                {
                    return(false);
                }

                foreach (var item in OtherRects)
                {
                    if (MUtility.IsAreaContains(item, hand))
                    {
                        return(true);//如果存在,就可以直接返回了
                    }
                }
            }
            else
            {
                if (OtherSizes == null)
                {
                    return(false);
                }

                foreach (var item in OtherSizes)
                {
                    var screenPoint = MUtility.UIWorldToScreenPoint(item.transform.position);

                    if (MUtility.IsAreaContains(screenPoint, item.panelSize, hand))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }