Пример #1
0
        private static void GetTouchState(InputSystem input, ref NativeList <PointerState> pointers)
        {
            int touchCount = input.TouchCount();

            for (int i = 0; i < touchCount; i++)
            {
                if (pointers.Length == MaxPointers)
                {
                    break;
                }

                var  touch          = input.GetTouch(i);
                var  worldPoint     = input.TranslateScreenToWorld(new float2(touch.x, touch.y));
                bool touchDown      = touch.phase == TouchState.Began;
                bool touchUp        = touch.phase == TouchState.Ended;
                bool touchCancelled = touch.phase == TouchState.Canceled;

                var          touchPointerId = new PointerID(PointerType.Touch, touch.fingerId);
                bool         willGone       = touchUp;
                PointerState touchPointer   = new PointerState()
                {
                    id        = touchPointerId,
                    pos       = worldPoint.xy,
                    down      = touchDown,
                    up        = touchUp,
                    willGone  = willGone,
                    cancelled = touchCancelled
                };

                pointers.Add(touchPointer);
            }
        }
Пример #2
0
        private static void GetMouseState(InputSystem input, ref NativeList <PointerState> pointers)
        {
            if (pointers.Length == MaxPointers)
            {
                return;
            }

            var mousePos  = input.GetWorldInputPosition();
            var mouseDown = input.GetMouseButtonDown(0);
            var mouseUp   = input.GetMouseButtonUp(0);

            PointerState mouse = new PointerState()
            {
                id        = new PointerID(PointerType.Mouse, 0),
                pos       = mousePos.xy,
                down      = mouseDown,
                up        = mouseUp,
                willGone  = false,
                cancelled = false
            };

            pointers.Add(mouse);
        }