Пример #1
0
        public static T GetPooled(Touch touch, EventModifiers modifiers = EventModifiers.None)
        {
            T e = GetPooled();

            e.pointerId   = touch.fingerId + PointerId.touchPointerIdBase;
            e.pointerType = PointerType.touch;

            bool otherTouchDown = false;

            for (var i = PointerId.touchPointerIdBase;
                 i < PointerId.touchPointerIdBase + PointerId.touchPointerCount;
                 i++)
            {
                if (i != e.pointerId && PointerDeviceState.GetPressedButtons(i) != 0)
                {
                    otherTouchDown = true;
                    break;
                }
            }
            e.isPrimary = !otherTouchDown;

            if (touch.phase == TouchPhase.Began)
            {
                PointerDeviceState.PressButton(e.pointerId, 0);
                e.button = 0;
            }
            else if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
            {
                PointerDeviceState.ReleaseButton(e.pointerId, 0);
                e.button = 0;
            }
            else
            {
                e.button = -1;
            }

            e.pressedButtons     = PointerDeviceState.GetPressedButtons(e.pointerId);
            e.position           = touch.position;
            e.localPosition      = touch.position;
            e.deltaPosition      = touch.deltaPosition;
            e.deltaTime          = touch.deltaTime;
            e.clickCount         = touch.tapCount;
            e.pressure           = Mathf.Abs(touch.maximumPossiblePressure) > Mathf.Epsilon ? touch.pressure / touch.maximumPossiblePressure : 1f;
            e.tangentialPressure = 0;

            e.altitudeAngle  = touch.altitudeAngle;
            e.azimuthAngle   = touch.azimuthAngle;
            e.twist          = 0;
            e.radius         = new Vector2(touch.radius, touch.radius);
            e.radiusVariance = new Vector2(touch.radiusVariance, touch.radiusVariance);

            e.modifiers = modifiers;

            ((IPointerEventInternal)e).triggeredByOS = true;

            return(e);
        }
        public new static MouseUpEvent GetPooled(Event systemEvent)
        {
            bool flag = systemEvent != null;

            if (flag)
            {
                PointerDeviceState.ReleaseButton(PointerId.mousePointerId, systemEvent.button);
            }
            return(MouseEventBase <MouseUpEvent> .GetPooled(systemEvent));
        }
        private static MouseUpEvent MakeFromPointerEvent(IPointerEvent pointerEvent)
        {
            bool flag = pointerEvent != null && pointerEvent.button >= 0;

            if (flag)
            {
                PointerDeviceState.ReleaseButton(PointerId.mousePointerId, pointerEvent.button);
            }
            return(MouseEventBase <MouseUpEvent> .GetPooled(pointerEvent));
        }
        public static T GetPooled(Touch touch, EventModifiers modifiers = EventModifiers.None)
        {
            T pooled = EventBase <T> .GetPooled();

            pooled.pointerId   = touch.fingerId + PointerId.touchPointerIdBase;
            pooled.pointerType = PointerType.touch;
            bool flag = false;

            for (int i = PointerId.touchPointerIdBase; i < PointerId.touchPointerIdBase + PointerId.touchPointerCount; i++)
            {
                bool flag2 = i != pooled.pointerId && PointerDeviceState.GetPressedButtons(i) != 0;
                if (flag2)
                {
                    flag = true;
                    break;
                }
            }
            pooled.isPrimary = !flag;
            bool flag3 = touch.phase == TouchPhase.Began;

            if (flag3)
            {
                PointerDeviceState.PressButton(pooled.pointerId, 0);
                pooled.button = 0;
            }
            else
            {
                bool flag4 = touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled;
                if (flag4)
                {
                    PointerDeviceState.ReleaseButton(pooled.pointerId, 0);
                    pooled.button = 0;
                }
                else
                {
                    pooled.button = -1;
                }
            }
            pooled.pressedButtons     = PointerDeviceState.GetPressedButtons(pooled.pointerId);
            pooled.position           = touch.position;
            pooled.localPosition      = touch.position;
            pooled.deltaPosition      = touch.deltaPosition;
            pooled.deltaTime          = touch.deltaTime;
            pooled.clickCount         = touch.tapCount;
            pooled.pressure           = ((Mathf.Abs(touch.maximumPossiblePressure) > Mathf.Epsilon) ? (touch.pressure / touch.maximumPossiblePressure) : 1f);
            pooled.tangentialPressure = 0f;
            pooled.altitudeAngle      = touch.altitudeAngle;
            pooled.azimuthAngle       = touch.azimuthAngle;
            pooled.twist          = 0f;
            pooled.radius         = new Vector2(touch.radius, touch.radius);
            pooled.radiusVariance = new Vector2(touch.radiusVariance, touch.radiusVariance);
            pooled.modifiers      = modifiers;
            pooled.triggeredByOS  = true;
            return(pooled);
        }
Пример #5
0
        public static T GetPooled(Event systemEvent)
        {
            T e = GetPooled();

            Debug.Assert(IsMouse(systemEvent) || systemEvent.rawType == EventType.DragUpdated, "Unexpected event type: " + systemEvent.rawType + " (" + systemEvent.type + ")");

            switch (systemEvent.pointerType)
            {
            default:
                e.pointerType = PointerType.mouse;
                e.pointerId   = PointerId.mousePointerId;
                break;

            case UnityEngine.PointerType.Touch:
                e.pointerType = PointerType.touch;
                e.pointerId   = PointerId.touchPointerIdBase;
                break;

            case UnityEngine.PointerType.Pen:
                e.pointerType = PointerType.pen;
                e.pointerId   = PointerId.penPointerIdBase;
                break;
            }

            e.isPrimary = true;

            e.altitudeAngle  = 0;
            e.azimuthAngle   = 0;
            e.twist          = 0;
            e.radius         = Vector2.zero;
            e.radiusVariance = Vector2.zero;

            e.imguiEvent = systemEvent;

            if (systemEvent.rawType == EventType.MouseDown)
            {
                PointerDeviceState.PressButton(PointerId.mousePointerId, systemEvent.button);
                e.button = systemEvent.button;
            }
            else if (systemEvent.rawType == EventType.MouseUp)
            {
                PointerDeviceState.ReleaseButton(PointerId.mousePointerId, systemEvent.button);
                e.button = systemEvent.button;
            }
            else if (systemEvent.rawType == EventType.MouseMove)
            {
                e.button = -1;
            }

            e.pressedButtons = PointerDeviceState.GetPressedButtons(e.pointerId);
            e.position       = systemEvent.mousePosition;
            e.localPosition  = systemEvent.mousePosition;
            e.deltaPosition  = systemEvent.delta;
            e.clickCount     = systemEvent.clickCount;
            e.modifiers      = systemEvent.modifiers;

            switch (systemEvent.pointerType)
            {
            default:
                e.pressure = e.pressedButtons == 0 ? 0f : 0.5f;
                break;

            case UnityEngine.PointerType.Touch:
            case UnityEngine.PointerType.Pen:
                e.pressure = systemEvent.pressure;
                break;
            }

            e.tangentialPressure = 0;

            ((IPointerEventInternal)e).triggeredByOS = true;

            return(e);
        }
        public static T GetPooled(Event systemEvent)
        {
            T pooled = EventBase <T> .GetPooled();

            bool flag = !PointerEventBase <T> .IsMouse(systemEvent) && systemEvent.rawType != EventType.DragUpdated;

            if (flag)
            {
                Debug.Assert(false, string.Concat(new string[]
                {
                    "Unexpected event type: ",
                    systemEvent.rawType.ToString(),
                    " (",
                    systemEvent.type.ToString(),
                    ")"
                }));
            }
            UnityEngine.PointerType pointerType  = systemEvent.pointerType;
            UnityEngine.PointerType pointerType2 = pointerType;
            if (pointerType2 != UnityEngine.PointerType.Touch)
            {
                if (pointerType2 != UnityEngine.PointerType.Pen)
                {
                    pooled.pointerType = PointerType.mouse;
                    pooled.pointerId   = PointerId.mousePointerId;
                }
                else
                {
                    pooled.pointerType = PointerType.pen;
                    pooled.pointerId   = PointerId.penPointerIdBase;
                }
            }
            else
            {
                pooled.pointerType = PointerType.touch;
                pooled.pointerId   = PointerId.touchPointerIdBase;
            }
            pooled.isPrimary      = true;
            pooled.altitudeAngle  = 0f;
            pooled.azimuthAngle   = 0f;
            pooled.twist          = 0f;
            pooled.radius         = Vector2.zero;
            pooled.radiusVariance = Vector2.zero;
            pooled.imguiEvent     = systemEvent;
            bool flag2 = systemEvent.rawType == EventType.MouseDown;

            if (flag2)
            {
                PointerDeviceState.PressButton(PointerId.mousePointerId, systemEvent.button);
                pooled.button = systemEvent.button;
            }
            else
            {
                bool flag3 = systemEvent.rawType == EventType.MouseUp;
                if (flag3)
                {
                    PointerDeviceState.ReleaseButton(PointerId.mousePointerId, systemEvent.button);
                    pooled.button = systemEvent.button;
                }
                else
                {
                    bool flag4 = systemEvent.rawType == EventType.MouseMove;
                    if (flag4)
                    {
                        pooled.button = -1;
                    }
                }
            }
            pooled.pressedButtons = PointerDeviceState.GetPressedButtons(pooled.pointerId);
            pooled.position       = systemEvent.mousePosition;
            pooled.localPosition  = systemEvent.mousePosition;
            pooled.deltaPosition  = systemEvent.delta;
            pooled.clickCount     = systemEvent.clickCount;
            pooled.modifiers      = systemEvent.modifiers;
            UnityEngine.PointerType pointerType3 = systemEvent.pointerType;
            UnityEngine.PointerType pointerType4 = pointerType3;
            if (pointerType4 - UnityEngine.PointerType.Touch > 1)
            {
                pooled.pressure = ((pooled.pressedButtons == 0) ? 0f : 0.5f);
            }
            else
            {
                pooled.pressure = systemEvent.pressure;
            }
            pooled.tangentialPressure = 0f;
            pooled.triggeredByOS      = true;
            return(pooled);
        }