Ejemplo n.º 1
0
 public static void SafeRemoveEventListener(ITouchEventListener listener)
 {
     if (_instance != null)
     {
         _instance.RemoveEventListener(listener);
     }
 }
Ejemplo n.º 2
0
    public void RemoveEventListener(ITouchEventListener listener)
    {
//		Log.Debug("RemoveEventListener: " + listener.ToString());

        int count = _listeners.Count;

        for (int i = 0; i < count; i++)
        {
            if (listener == _listeners[i].listener)
            {
                _listeners.RemoveAt(i);
                return;
            }
        }
    }
Ejemplo n.º 3
0
    public void AddEventListener(ITouchEventListener listener, int priority = -1)
    {
//		Log.Debug("AddEventListener: " + listener.ToString());

        int count = _listeners.Count;

        if (count < 1 || priority < _listeners[count - 1].priority)
        {
            _listeners.Add(new TouchEventListener(listener, priority));
        }
        else
        {
            for (int i = 0; i < count; i++)
            {
                if (priority >= _listeners[i].priority)
                {
                    _listeners.Insert(i, new TouchEventListener(listener, priority));
                    break;
                }
            }
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        if (!_isEnabled)
        {
            return;
        }

        if (_listeners.Count < 1)
        {
            return;
        }

        // Touch input
        if (Input.touchCount > 0)
        {
            // Get touch
            Touch touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Began)
            {
                _listener = null;

                if (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject())
                {
                    Vector3 position = ScreenToWorldPoint(touch.position);

                    int count = _listeners.Count;

                    for (int i = 0; i < count; i++)
                    {
                        ITouchEventListener listener = _listeners[i].listener;

                        if (listener.OnTouchPressed(position))
                        {
                            _listener = listener;
                            break;
                        }
                    }
                }
            }
            else
            {
                if (_listener != null)
                {
                    if (touch.phase == TouchPhase.Moved)
                    {
                        if (!_listener.OnTouchMoved(ScreenToWorldPoint(touch.position)))
                        {
                            _listener = null;
                        }
                    }
                    else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
                    {
                        _listener.OnTouchReleased(ScreenToWorldPoint(touch.position));
                    }
                }
            }
        }
        // Mouse input
        else
        {
            if (Input.GetMouseButtonDown(0))
            {
                _listener = null;

                if (EventSystem.current == null || !EventSystem.current.IsPointerOverGameObject())
                {
                    Vector3 position = ScreenToWorldPoint(Input.mousePosition);

                    int count = _listeners.Count;

                    for (int i = 0; i < count; i++)
                    {
                        ITouchEventListener listener = _listeners[i].listener;

                        if (listener.OnTouchPressed(position))
                        {
                            _listener = listener;
                            break;
                        }
                    }
                }
            }
            else
            {
                if (_listener != null)
                {
                    if (Input.GetMouseButton(0))
                    {
                        if (!_listener.OnTouchMoved(ScreenToWorldPoint(Input.mousePosition)))
                        {
                            _listener = null;
                        }
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        _listener.OnTouchReleased(ScreenToWorldPoint(Input.mousePosition));
                    }
                }
            }
        }
    }
Ejemplo n.º 5
0
 public TouchEventListener(ITouchEventListener listener, int priority)
 {
     this.listener = listener;
     this.priority = priority;
 }