Beispiel #1
0
        protected abstract void OnUserPointerUp(PointerEventData eventData);    //用户手指或鼠标松开事件响应


        /// <summary>
        /// 检测到手指或鼠标按下时开启协程,判断用户本次操作类型
        /// </summary>
        /// <param name="data">Data.</param>
        public virtual void OnPointerDown(PointerEventData data)
        {
            UserOperationCallBack longPressCallBack = OnUserLongPress;

            Rect detectSourceRect = (transform as RectTransform).rect;

            checkOperationTypeCoroutine = CheckUserOperationType(data, longPressCallBack);

            StartCoroutine(checkOperationTypeCoroutine);
        }
Beispiel #2
0
        /// <summary>
        /// 判断用户本次点击事件操作类型的协程
        /// </summary>
        /// <returns>The user operation type.</returns>
        /// <param name="data">点击起始时刻的点击信息数据</param>
        /// <param name="longPressCallBack">长按事件回调.</param>
        private IEnumerator CheckUserOperationType(PointerEventData data, UserOperationCallBack longPressCallBack)
        {
            float pressTime = Time.realtimeSinceStartup;

            mOperationType = UserOperationType.ShortClick;

            Vector3 pointerWorldPos;

            Vector3[] worldCorners = new Vector3[4];

            (transform as RectTransform).GetWorldCorners(worldCorners);

            bool pointerInsideDetectSource = true;

            while (Time.realtimeSinceStartup - pressTime < minPressTimeToDrag)
            {
                RectTransformUtility.ScreenPointToWorldPointInRectangle(transform as RectTransform, Input.mousePosition, data.pressEventCamera, out pointerWorldPos);

                pointerInsideDetectSource = CheckPointerInsideDetectSource(worldCorners, pointerWorldPos);

                if (!pointerInsideDetectSource)
                {
                    mOperationType = UserOperationType.Cancel;
                    break;
                }

                yield return(null);
            }

            if (pointerInsideDetectSource)
            {
                mOperationType = UserOperationType.LongPress;

                OnUserLongPress(data);
            }

            checkOperationTypeCoroutine = null;
        }