Пример #1
0
    public void Feed(XTouchItem touch)
    {
        _one    |= OneUpdate(touch);
        _one_up |= OneUpUpdate(touch);

        if ((!_bFreeze) && ((_finger_id == -1 && touch.FingerId != XVirtualTab.singleton.FingerId) || _finger_id == touch.FingerId))
        {
            if (touch.Phase == TouchPhase.Began)
            {
                _start       = touch.Position;
                _swype_start = _start;
                _bTouch      = true;
            }

            if (_bTouch)
            {
                if (XTouch.IsActiveTouch(touch))
                {
                    _gesturepos = touch.Position;
                    _bswype     = SwypeUpdate(touch);
                    if (_bswype)
                    {
                        _finger_id = touch.FingerId;
                    }
                }
                else
                {
                    Cancel();
                }
            }
        }
    }
Пример #2
0
    private void HandleTouch(XTouchItem touch)
    {
        bool isOnUI = PointOnUI(touch.Position);

        if (isOnUI)
        {
            switch (touch.Phase)
            {
            case TouchPhase.Began:
                if (touch.Fake)
                {
                    touch.faketouch.phase = TouchPhase.Canceled;
                }
                else
                {
                    touch.Convert2FakeTouch(TouchPhase.Canceled);
                }
                break;

            case TouchPhase.Moved:
            case TouchPhase.Stationary:
            case TouchPhase.Canceled:
            case TouchPhase.Ended:
                break;
            }
        }

        XVirtualTab.singleton.Feed(touch);
        XGesture.singleton.Feed(touch);
    }
Пример #3
0
 public XKeyboard()
 {
     for (int i = 0; i < XTouch.MaxTouchCount; i++)
     {
         _touches[i] = new XTouchItem();
     }
 }
Пример #4
0
 private bool OneUpdate(XTouchItem touch)
 {
     if (touch.Phase == TouchPhase.Began &&
         (touch.FingerId == XTouch.mouseFingerID ||
          touch.FingerId == XTouch.keyboardFinderID))
     {
         _touchpos = touch.Position;
         return(true);
     }
     return(false);
 }
Пример #5
0
 public void Feed(XTouchItem touch)
 {
     if (!_bFreeze && ((_finger_id == -1 && touch.FingerId != XGesture.singleton.FingerId) || _finger_id == touch.FingerId))
     {
         if (_bFeeding)
         {
             if (XTouch.IsActiveTouch(touch))
             {
                 CalcMove(touch, false);
             }
             else
             {
                 Cancel();
             }
         }
         else
         {
             if (_bTouch)
             {
                 if (XTouch.IsActiveTouch(touch))
                 {
                     Vector2 delta = touch.Position - _center;
                     if (delta.sqrMagnitude > _dead_zone * _dead_zone)
                     {
                         _bFeeding = true;
                         CalcMove(touch, true);
                     }
                 }
                 else
                 {
                     Cancel();
                 }
             }
             else
             {
                 if (touch.Phase == TouchPhase.Began && touch.Position.x < Screen.width * 0.5f)
                 {
                     _bTouch    = true;
                     _center    = touch.Position;
                     _finger_id = touch.FingerId;
                 }
             }
         }
     }
 }
Пример #6
0
 private bool SwypeUpdate(XTouchItem touch)
 {
     if (touch.Phase == TouchPhase.Moved)
     {
         _end = touch.Position;
         Vector2 delta = _end - _swype_start;
         float   endAt = Time.time;
         _swype_dis = delta.magnitude;
         if (_swype_dis > _dead_zone)
         {
             _swype_start = _end;
             _swypedir.x  = delta.x;
             _swypedir.y  = 0;
             _swypedir.z  = delta.y;
             _swypedir.Normalize();
             _gesturepos = _end;
             return(true);
         }
     }
     return(false);
 }
Пример #7
0
    private bool OneUpUpdate(XTouchItem touch)
    {
        if (touch.FingerId != XTouch.mouseFingerID && touch.FingerId != XTouch.keyboardFinderID)
        {
            return(false);
        }

        if (touch.Phase == TouchPhase.Began)
        {
            if (!Application.isMobilePlatform && touch.FingerId == XTouch.keyboardFinderID)
            {
                return(false);
            }

            //only process mouse point but keyboard for Editor Mode
            _touchpos           = touch.Position;
            _last_touch_down_at = Time.time;
        }
        else if (touch.Phase == TouchPhase.Canceled || touch.Phase == TouchPhase.Ended)
        {
            float deltaT = Time.time - _last_touch_down_at;
            if (deltaT < 0.5f / Time.timeScale)
            {
                Vector2 delta;
                delta.x = _touchpos.x - touch.Position.x;
                delta.y = _touchpos.y - touch.Position.y;

                if (delta.magnitude < _dead_zone)
                {
                    _touchpos = touch.Position;
                    return(true);
                }
            }
        }
        return(false);
    }
Пример #8
0
    private void CalcMove(XTouchItem touch, bool newly)
    {
        TabCulling();

        Vector2 dir = touch.Position - _center;

        if (!newly && Application.isEditor && touch.FingerId == 1)
        {
            float tab_round_angle = 480 * Time.deltaTime;

            float angles = Vector2.Angle(_tab_dir, dir);

            if (angles > tab_round_angle)
            {
                bool hands_before = XCommon.singleton.Clockwise(_tab_dir, dir);
                _tab_dir = XCommon.singleton.HorizontalRotateVetor2(_tab_dir, hands_before ? tab_round_angle : -tab_round_angle, false);
                bool hands_end = XCommon.singleton.Clockwise(_tab_dir, dir);

                if (hands_before != hands_end)
                {
                    _tab_dir = dir;
                }
            }
            else
            {
                _tab_dir = dir;
            }
        }
        else
        {
            _tab_dir = dir;
        }

        float radius = _tab_dir.magnitude;

        if (radius > _max_distance)
        {
            radius = _max_distance;
            TabCulling();
        }

        float angle      = Vector2.Angle(Vector2.up, _tab_dir);
        bool  bClockwise = XCommon.singleton.Clockwise(Vector2.up, _tab_dir);

        if (XScene.singleton.GameCamera != null && XScene.singleton.GameCamera.CameraTrans != null)
        {
            Vector3 forward = XScene.singleton.GameCamera.CameraTrans.forward;
            forward.y = 0;
            forward.Normalize();
            _direction = XCommon.singleton.HorizontalRotateVetor3(forward, bClockwise ? angle : -angle);
        }
#if Native
        if (NativeScene.singleton.camera != null)
        {
            Vector3 forward = NativeScene.singleton.camera.transform.forward;
            forward.y = 0;
            forward.Normalize();
            _direction = XCommon.singleton.HorizontalRotateVetor3(forward, bClockwise ? angle : -angle);
        }
#endif
        JoyStickDlg.singleton.Show(true, _center);
        JoyStickDlg.singleton.SetOffsetPos(radius, (bClockwise ? angle : 360.0f - angle) - 90);
    }
Пример #9
0
 public static bool IsActiveTouch(XTouchItem touch)
 {
     return(touch.Phase != TouchPhase.Ended &&
            touch.Phase != TouchPhase.Canceled);
 }