private void OnUpdate()
        {
            pointersNextValidation -= Time.unscaledDeltaTime;
            if (pointersNextValidation <= 0f)
            {
                pointersNextValidation = POINTERS_VALIDATION_INTERVAL;
                ValidatePointers();
            }

            for (int i = listeners.Count - 1; i >= 0; i--)
            {
                if (listeners[i].OnUpdate(mousePointers, touchPointers, activeListener))
                {
                    if (activeListener == null || activeListener.Priority < listeners[i].Priority)
                    {
                        activeListener = listeners[i];
                    }
                }
                else if (activeListener == listeners[i])
                {
                    activeListener = null;
                }
            }

            for (int i = 0; i < mousePointers.Count; i++)
            {
                mousePointers[i].delta = new Vector2(0f, 0f);
            }

            for (int i = 0; i < touchPointers.Count; i++)
            {
                touchPointers[i].delta = new Vector2(0f, 0f);
            }
        }
        public void RemoveListener(ISimpleInputDraggableMultiTouch listener)
        {
            listeners.Remove(listener);

            if (activeListener == listener)
            {
                activeListener = null;
            }
        }
        public void AddListener(ISimpleInputDraggableMultiTouch listener)
        {
            int priority = listener.Priority;
            int i        = 0;

            while (i < listeners.Count && listeners[i].Priority < priority)
            {
                i++;
            }

            listeners.Insert(i, listener);
        }
Exemplo n.º 4
0
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            xAxis.value = 0f;
            yAxis.value = 0f;

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            PointerEventData pointer = GetSatisfyingPointer(mousePointers, touchPointers);

            if (pointer == null)
            {
                return(false);
            }

            m_value = pointer.delta * SimpleInputUtils.ResolutionMultiplier * sensitivity;

            xAxis.value = invertHorizontal ? -m_value.x : m_value.x;
            yAxis.value = invertVertical ? -m_value.y : m_value.y;

            return(true);
        }
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            axis.value = 0f;

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            if (touchPointers.Count < 2)
            {
#pragma warning disable 0252
                if (activeListener == this && touchPointers.Count == 1)
                {
                    touchPointers[0].pressPosition = touchPointers[0].position;
                }
#pragma warning restore 0252

                return(false);
            }

            PointerEventData touch1 = touchPointers[touchPointers.Count - 1];
            PointerEventData touch2 = touchPointers[touchPointers.Count - 2];

            float pinchAmount = (touch2.delta - touch1.delta).magnitude;
            bool  zoomingOut  = (touch2.position - touch1.position).sqrMagnitude < ((touch2.position - touch2.delta) - (touch1.position - touch1.delta)).sqrMagnitude;
            if (invertValue != zoomingOut)
            {
                pinchAmount = -pinchAmount;
            }

            axis.value = pinchAmount * sensitivity * SimpleInputUtils.ResolutionMultiplier;
            return(true);
        }
Exemplo n.º 6
0
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            Input.ResetValue();

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            PointerEventData pointer = GetSatisfyingPointer(mousePointers, touchPointers);

            if (pointer == null)
            {
                return(false);
            }

#pragma warning disable 0252
            if (!IsSwipeSatisfied(pointer))
            {
                return(activeListener == this);
            }
#pragma warning restore 0252

            Input.value = Value;
            return(true);
        }
Exemplo n.º 7
0
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            print(touchPointers.Count);
            axis.value = 0f;

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            if (touchPointers.Count < 2)
            {
#pragma warning disable 0252
                if (activeListener == this && touchPointers.Count == 1)
                {
                    touchPointers[0].pressPosition = touchPointers[0].position;
                }
#pragma warning restore 0252

                return(false);
            }

            PointerEventData touch1 = touchPointers[touchPointers.Count - 1];
            PointerEventData touch2 = touchPointers[touchPointers.Count - 2];

            Vector2 deltaPosition     = touch2.position - touch1.position;
            Vector2 prevDeltaPosition = deltaPosition - (touch2.delta - touch1.delta);

            float deltaAngle = (Mathf.Atan2(prevDeltaPosition.y, prevDeltaPosition.x) - Mathf.Atan2(deltaPosition.y, deltaPosition.x)) * MULTIPLIER;
            if (deltaAngle > 180f)
            {
                deltaAngle -= 360f;
            }
            else if (deltaAngle < -180f)
            {
                deltaAngle += 360f;
            }

            axis.value = clockwise ? deltaAngle * sensitivity : -deltaAngle * sensitivity;
            return(true);
        }
Exemplo n.º 8
0
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            Input.ResetValue();

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            PointerEventData pointer = GetSatisfyingPointer(mousePointers, touchPointers);

            if (pointer == null)
            {
                return(false);
            }

            if (!IsSwipeSatisfied(pointer))
            {
                return(ReferenceEquals(activeListener, this));
            }

            Input.value = Value;
            return(true);
        }
Exemplo n.º 9
0
        public bool OnUpdate(List <PointerEventData> mousePointers, List <PointerEventData> touchPointers, ISimpleInputDraggableMultiTouch activeListener)
        {
            horizontal.value = 0f;
            vertical.value   = 0f;

            if (activeListener != null && activeListener.Priority > Priority)
            {
                return(false);
            }

            if (touchPointers.Count < 2)
            {
                if (ReferenceEquals(activeListener, this) && touchPointers.Count == 1)
                {
                    touchPointers[0].pressPosition = touchPointers[0].position;
                }

                return(false);
            }

            PointerEventData touch1 = touchPointers[touchPointers.Count - 1];
            PointerEventData touch2 = touchPointers[touchPointers.Count - 2];

            Vector2 pinchAmount = sensitivity * SimpleInputUtils.ResolutionMultiplier * (touch1.delta + touch2.delta);

            if (invertValue)
            {
                pinchAmount = -pinchAmount;
            }

            horizontal.value = pinchAmount.x;
            vertical.value   = pinchAmount.y;

            return(true);
        }