Esempio n. 1
0
 public override void update(float elapsedTime)
 {
     base.update(elapsedTime);
     // 确保RectTransform和BoxCollider一样大
     if (mRectTransform != null && mBoxCollider != null)
     {
         if (mRectTransform.rect.width != mBoxCollider.size.x || mRectTransform.rect.height != mBoxCollider.size.y)
         {
             mBoxCollider.size   = mRectTransform.rect.size;
             mBoxCollider.center = multiVector2(mRectTransform.rect.size, new Vector2(0.5f, 0.5f) - mRectTransform.pivot);
         }
     }
     // 长按检测
     if ((mOnLongPress != null || mOnLongPressing != null) && mPressing && mPressedTime >= 0.0f)
     {
         if (mLongPressLengthThreshold < 0.0f || lengthLess(mMouseDownPosition - getMousePosition(), mLongPressLengthThreshold))
         {
             mPressedTime += elapsedTime;
             if (mOnLongPressing != null)
             {
                 float progress = !isFloatZero(mLongPressTimeThreshold) ? mPressedTime / mLongPressTimeThreshold : 0.0f;
                 clampMax(ref progress, 1.0f);
                 mOnLongPressing(progress);
             }
             if (mPressedTime >= mLongPressTimeThreshold)
             {
                 mOnLongPress?.Invoke();
                 mPressedTime = -1.0f;
             }
         }
         else
         {
             mPressedTime = -1.0f;
             mOnLongPressing?.Invoke(0.0f);
         }
     }
     // 双击计时
     if (mLastClickTime >= 0.0f && mLastClickTime < CommonDefine.DOUBLE_CLICK_THRESHOLD)
     {
         mLastClickTime += elapsedTime;
     }
     // 超过一定时间后停止计时
     else if (mLastClickTime >= CommonDefine.DOUBLE_CLICK_THRESHOLD)
     {
         mLastClickTime = -1.0f;
     }
     // 检测世界缩放值是否有变化
     if (!isVectorEqual(mLastWorldScale, getWorldScale()))
     {
         onWorldScaleChanged(mLastWorldScale);
         mLastWorldScale = getWorldScale();
     }
 }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (Input.touchCount > 0)
        {
            _touch       = Input.GetTouch(0);
            _touchTimer += Time.deltaTime;
            switch (_touch.phase)
            {
            case TouchPhase.Ended:
                if (_touch.tapCount >= 2)
                {
                    StopAllCoroutines();
                    if (OnDoubleClick != null)
                    {
                        OnDoubleClick.Invoke(_touch);
                        Debug.Log("Working");
                    }
                }
                else if (_touchTimer < LongPressThreshold)
                {
                    StartCoroutine(CheckSingleClick());
                }
                else if (_touchTimer > LongPressThreshold)
                {
                    StopAllCoroutines();
                    OnRelease.Invoke(_touch);
                }

                break;

            case TouchPhase.Moved:
                if (_touchTimer > LongPressThreshold)
                {
                    if (OnLongPressing != null)
                    {
                        OnLongPressing.Invoke(_touch);
                    }
                }
                break;

            case TouchPhase.Stationary:
                if (_touchTimer > LongPressThreshold)
                {
                    if (OnLongPressing != null)
                    {
                        OnLongPressing.Invoke(_touch);
                    }
                }
                break;

            default:
                break;
            }
        }
        else
        {
            _touchTimer = 0;
        }
    }
Esempio n. 3
0
 public override void update(float elapsedTime)
 {
     base.update(elapsedTime);
     // 长按检测
     if ((mOnLongPress != null || mOnLongPressing != null) && mPressing && mPressedTime >= 0.0f)
     {
         if (mLongPressLengthThreshold < 0.0f || lengthLess(mMouseDownPosition - getMousePosition(), mLongPressLengthThreshold))
         {
             mPressedTime += elapsedTime;
             if (mOnLongPressing != null)
             {
                 float progress = !isFloatZero(mLongPressTimeThreshold) ? mPressedTime / mLongPressTimeThreshold : 0.0f;
                 clampMax(ref progress, 1.0f);
                 mOnLongPressing(progress);
             }
             if (mPressedTime >= mLongPressTimeThreshold)
             {
                 mOnLongPress?.Invoke();
                 mPressedTime = -1.0f;
             }
         }
         else
         {
             mPressedTime = -1.0f;
             mOnLongPressing?.Invoke(0.0f);
         }
     }
     // 双击计时
     if (mLastClickTime >= 0.0f && mLastClickTime < FrameDefine.DOUBLE_CLICK_THRESHOLD)
     {
         mLastClickTime += elapsedTime;
     }
     // 超过一定时间后停止计时
     else if (mLastClickTime >= FrameDefine.DOUBLE_CLICK_THRESHOLD)
     {
         mLastClickTime = -1.0f;
     }
     // 检测世界缩放值是否有变化
     if (!isVectorEqual(mLastWorldScale, getWorldScale()))
     {
         onWorldScaleChanged(mLastWorldScale);
         mLastWorldScale = getWorldScale();
     }
 }