Beispiel #1
0
    private void EndSingleTouch(TouchWrapper touch,
                                Transform target,
                                Vector3 location,
                                Vector3 direction,
                                Vector3 groundPosition,
                                bool hasValidNavPoint)
    {
        float singleTouchDuration = Time.time - _singleTouchStartTime;

        if (singleTouchDuration < TapLength)
        {
            if (Time.time - _lastTapTime > DoubleTapLength)
            {
                TapEvent tapEvent = (null != target) ? new TapEvent(touch.position, target, location) : new TapEvent(touch.position, location);
                tapEvent.direction        = direction;
                tapEvent.groundPosition   = groundPosition;
                tapEvent.hasValidNavPoint = hasValidNavPoint;
#if BUFFER_SINGLE_TAPS
                StartCoroutine(QueueSingleTap(tapEvent));
#else
                _lastTapTime  = Time.time;
                _didDoubleTap = false;
                RaiseEvent(tapEvent);
#endif
            }
            else
            {
                DoubleTapEvent doubleTapEvent = (null != target) ? new DoubleTapEvent(touch.position, target, location) : new DoubleTapEvent(touch.position, location);
                doubleTapEvent.direction = direction;
                DoDoubleTap(doubleTapEvent);
            }
        }
        else if (_touchStartedOnPlayer)
        {
            DragFromPlayerGestureEndEvent evt = null;
            if (target)
            {
                evt = new DragFromPlayerGestureEndEvent(touch.position, target);
            }
            else
            {
                evt = new DragFromPlayerGestureEndEvent(touch.position, location);
            }
            evt.direction      = direction;
            evt.groundPosition = groundPosition;
            RaiseEvent(evt);
            _touchStartedOnPlayer = false;
        }

        TouchEndEvent endEvent = (TouchEndEvent)CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).GetNext();;
        if (target != null)
        {
            endEvent.Initialize(touch.position, target, location);
        }
        else
        {
            endEvent.Initialize(touch.position, location);
        }
        endEvent.direction      = direction;
        endEvent.groundPosition = groundPosition;
        RaiseEvent(endEvent);
        CodeObjectManager.GetEventManager(typeof(TouchEndEvent)).Destroy(endEvent);

        //check for flick gesture
        float flick_history_check = 1.5f;
        float time_look_back      = 0.0f;
        int   i           = 0;
        int   touch_index = m_touch_history_index - 1 > 0 ? m_touch_history_index - 1: TOUCH_HISTORY_LENGTH - 1;

        Vector3 flick_vel  = Vector3.zero;
        float   last_time  = _touchHistory[touch_index]._time;
        Vector3 last_flick = touch.position;
        while (time_look_back < flick_history_check && i < TOUCH_HISTORY_LENGTH - 1)
        {
            if (_touchHistory[touch_index]._time == 0.0f)
            {
                break;
            }

            float time = last_time - _touchHistory[touch_index]._time;
            last_time = _touchHistory[touch_index]._time;

            time_look_back += time;
            flick_vel      += _touchHistory[touch_index]._position - last_flick;
            last_flick      = _touchHistory[touch_index]._position;

            i++;
            touch_index = touch_index - 1 > 0 ? touch_index - 1 : TOUCH_HISTORY_LENGTH - 1;
        }

        //EB.Debug.Log (i);
        if (time_look_back > 0.0f)
        {
            flick_vel *= time_look_back;
            if (flick_vel.magnitude > 0.2f)
            {
                FlickEvent flickEvent = new FlickEvent();
                flickEvent.Initialize(touch.position, flick_vel);
                RaiseEvent(flickEvent);
            }
            else
            {
                //EB.Debug.Log ("VEL FAIL");
            }
        }
        else
        {
            //EB.Debug.Log ("TIME FAIL");
        }


        ResetTouchHistory();
    }
Beispiel #2
0
    private void UpdateSingleTouch(TouchWrapper touch,
                                   Transform target,
                                   Vector3 location,
                                   Vector3 direction,
                                   Vector3 groundPosition,
                                   bool hasValidNavPoint)
    {
        float touchDuration = Time.time - _singleTouchStartTime;

        float selfSelectRadiusSq = GlobalBalanceData.Instance.selfSelectRadius;

        selfSelectRadiusSq *= selfSelectRadiusSq;

        if (touchDuration < TapLength)
        {
            // Do nothing yet
        }
        else if (!_longPressStarted)
        {
            // This press is longer than a tap
            _longPressStarted = true;

            TouchStartEvent startEvent = (TouchStartEvent)CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).GetNext();
            if (target)
            {
                startEvent.Initialize(touch.position, target, location);
            }
            else
            {
                startEvent.Initialize(touch.position, location);
            }
            startEvent.direction      = direction;
            startEvent.groundPosition = groundPosition;
            startEvent.deltaPosition  = touch.deltaPosition;
            RaiseEvent(startEvent);
            CodeObjectManager.GetEventManager(typeof(TouchStartEvent)).Destroy(startEvent);
        }
        else if (_touchStartedOnPlayer)
        {
            if (!_playerLongPressStarted)
            {
                if (GameUtils.GetDistSqXZ(groundPosition, _playerTransform.position) > selfSelectRadiusSq)
                {
                    DragFromPlayerGestureStartEvent evt = null;
                    if (target)
                    {
                        evt = new DragFromPlayerGestureStartEvent(touch.position, target);
                    }
                    else
                    {
                        evt = new DragFromPlayerGestureStartEvent(touch.position, location);
                    }
                    evt.direction      = direction;
                    evt.groundPosition = groundPosition;
                    RaiseEvent(evt);
                    _playerLongPressStarted = true;
                }
            }
            else
            {
                DragFromPlayerGestureUpdateEvent evt = null;
                if (target)
                {
                    evt = new DragFromPlayerGestureUpdateEvent(touch.position, target);
                }
                else
                {
                    evt = new DragFromPlayerGestureUpdateEvent(touch.position, location);
                }
                evt.direction      = direction;
                evt.groundPosition = groundPosition;
                RaiseEvent(evt);
            }
        }
        else
        {
            TouchUpdateEvent updateEvent = (TouchUpdateEvent)CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).GetNext();;
            if (target != null)
            {
                updateEvent.Initialize(touch.position, target, location);
            }
            else
            {
                updateEvent.Initialize(touch.position, location);
            }
            updateEvent.direction        = direction;
            updateEvent.groundPosition   = groundPosition;
            updateEvent.hasValidNavPoint = hasValidNavPoint;
            RaiseEvent(updateEvent);
            CodeObjectManager.GetEventManager(typeof(TouchUpdateEvent)).Destroy(updateEvent);
        }

        //add the touch to the touch history for gesture checking on end
        _touchHistory[m_touch_history_index]._time     = Time.realtimeSinceStartup;
        _touchHistory[m_touch_history_index]._position = touch.position;
        m_touch_history_index = (m_touch_history_index + 1) % TOUCH_HISTORY_LENGTH;
    }