Exemplo n.º 1
0
 public static void invoke(UnityEventTouchRollerEventData ev, TouchRollerEventData roller_ev)
 {
     for (int i = 0; i < ev.GetPersistentEventCount(); i++)
     {
         ((MonoBehaviour)ev.GetPersistentTarget(i)).SendMessage(ev.GetPersistentMethodName(i), roller_ev);
     }
 }
Exemplo n.º 2
0
        void Update()
        {
            if (m_touch_finger_id == -1)
            {
                Touch touch = PlatformInput.g.getTouchInRectTransform(m_RectTransform);
                if (touch.fingerId >= 0)
                {
                    if (touch.phase == TouchPhase.Began)
                    {
                        m_touch_finger_id        = touch.fingerId;
                        m_touch_initial_position = touch.position;

                        m_ev.is_cancel_roll = false;
                        m_ev.value          = 0;
                        UnityEventTouchRollerEventData.invoke(m_onRollStart, m_ev);
                        if (m_ev.is_cancel_roll)
                        {
                            m_touch_finger_id = -1;
                        }
                    }
                }
            }
            else
            {
                Touch touch = PlatformInput.g.getTouchByFingerID(m_touch_finger_id);
                if (touch.fingerId == m_touch_finger_id)
                {
                    Vector2 pos   = touch.position - m_touch_initial_position;
                    float   value = pos.x * (m_value_per_width / m_RectTransform.rect.width);
                    value = Mathf.Clamp(value, -m_value_per_width, m_value_per_width);

                    if (touch.phase == TouchPhase.Moved)
                    {
                        if (RectTransformUtility.RectangleContainsScreenPoint(m_RectTransform, touch.position))
                        {
                            m_last_correct_value = value;

                            m_ev.is_cancel_roll = false;
                            m_ev.value          = value;

                            UnityEventTouchRollerEventData.invoke(m_onRoll, m_ev);
                            if (m_ev.is_cancel_roll)
                            {
                                m_touch_finger_id = -1;
                            }
                        }
                    }
                    else

                    if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
                    {
                        m_ev.is_cancel_roll = false;
                        m_ev.value          = value;

                        if (!RectTransformUtility.RectangleContainsScreenPoint(m_RectTransform, touch.position))
                        {
                            m_ev.value = m_last_correct_value;
                        }

                        UnityEventTouchRollerEventData.invoke(m_onRollEnd, m_ev);
                        m_touch_finger_id = -1;
                    }
                }
                else
                {//error
                    m_touch_finger_id = -1;
                }
            }
        }