Пример #1
0
 void ProcessTouchMoveEvent(TouchState[] touches)
 {
     for (var i = 0; i < touches.Length; i++)
     {
         UnityInputSystem.QueueStateEvent(RemoteTouchscreen, touches[i]);
     }
 }
Пример #2
0
 void ProcessMouseMoveEvent(short x, short y, byte button)
 {
     UnityEngine.Vector2Int pos   = new UnityEngine.Vector2Int(x, y);
     UnityEngine.Vector2Int delta = pos - m_prevMousePos;
     UnityInputSystem.QueueStateEvent(RemoteMouse, new MouseState {
         position = pos,
         delta    = delta,
         buttons  = button
     });
     m_prevMousePos = pos;
 }
Пример #3
0
        void ChangeEndStateUnusedTouches(TouchState[] touches)
        {
            int touchCount = Touch.activeTouches.Count;

            for (var i = 0; i < touchCount; i++)
            {
                int touchId = Touch.activeTouches[i].touchId;
                if (!Array.Exists(touches, v => v.touchId == touchId))
                {
                    if (Touch.activeTouches[i].phase == TouchPhase.Ended)
                    {
                        continue;
                    }
                    UnityInputSystem.QueueStateEvent(RemoteTouchscreen, new TouchState
                    {
                        touchId  = touchId,
                        phase    = TouchPhase.Ended,
                        position = Touch.activeTouches[i].screenPosition
                    });
                }
            }
        }
Пример #4
0
        void ProcessKeyEvent(KeyboardEventType state, bool repeat, byte keyCode, char character)
        {
            switch (state)
            {
            case KeyboardEventType.KeyDown:
                if (!repeat)
                {
                    m_keyboardState.Set((Key)keyCode, true);
                    UnityInputSystem.QueueStateEvent(RemoteKeyboard, m_keyboardState);
                }
                if (character != 0)
                {
                    UnityInputSystem.QueueTextEvent(RemoteKeyboard, character);
                }
                break;

            case KeyboardEventType.KeyUp:
                m_keyboardState.Set((Key)keyCode, false);
                UnityInputSystem.QueueStateEvent(RemoteKeyboard, m_keyboardState);
                break;
            }
        }
Пример #5
0
 void ProcessMouseWheelEvent(float scrollX, float scrollY)
 {
     UnityInputSystem.QueueStateEvent(RemoteMouse, new MouseState {
         scroll = new UnityEngine.Vector2(scrollX, scrollY)
     });
 }
Пример #6
0
//---------------------------------------------------------------------------------------------------------------------

        public void ProcessInput(byte[] bytes)
        {
            if (bytes == null)
            {
                throw new ArgumentNullException();
            }
            if (bytes.Length == 0)
            {
                throw new ArgumentException("byte length is zero");
            }

            switch ((EventType)bytes[0])
            {
            case EventType.Keyboard:
                var type      = (KeyboardEventType)bytes[1];
                var repeat    = bytes[2] == 1;
                var key       = bytes[3];
                var character = (char)bytes[4];
                ProcessKeyEvent(type, repeat, key, character);
                break;

            case EventType.Mouse:
                var deltaX = BitConverter.ToInt16(bytes, 1);
                var deltaY = BitConverter.ToInt16(bytes, 3);
                var button = bytes[5];
                ProcessMouseMoveEvent(deltaX, deltaY, button);
                break;

            case EventType.MouseWheel:
                var scrollX = BitConverter.ToSingle(bytes, 1);
                var scrollY = BitConverter.ToSingle(bytes, 5);
                ProcessMouseWheelEvent(scrollX, scrollY);
                break;

            case EventType.Touch:
            {
                var length  = bytes[1];
                var index   = 2;
                var touches = new TouchState[length];
                for (int i = 0; i < length; i++)
                {
                    const int INPUTSYSTEM_ZERO_ID_GUARD = 128;         //ID 0 is reserved by inputsystem
                    int       identifier = BitConverter.ToInt32(bytes, index) + INPUTSYSTEM_ZERO_ID_GUARD;
                    index += 4;
                    var phase = (UnityEngine.InputSystem.TouchPhase)bytes[index];
                    index += 1;
                    var pageX = BitConverter.ToInt16(bytes, index);
                    index += 2;
                    var pageY = BitConverter.ToInt16(bytes, index);
                    index += 2;
                    var force = BitConverter.ToSingle(bytes, index);
                    index     += 4;
                    touches[i] = new TouchState
                    {
                        touchId  = identifier,
                        phase    = phase,
                        position = new UnityEngine.Vector2Int(pageX, pageY),
                        pressure = force
                    };
                }
                ProcessTouchMoveEvent(touches);
                if (Touch.activeTouches.Count > length)
                {
                    ChangeEndStateUnusedTouches(touches);
                }
            }

            break;

            case EventType.ButtonClick:
                var elementId = BitConverter.ToInt16(bytes, 1);
                ProcessButtonClickEvent(elementId);
                break;

            case EventType.Gamepad:
            {
                GamepadEventType gamepadEventType = (GamepadEventType)bytes[1];

                switch (gamepadEventType)
                {
                case GamepadEventType.ButtonDown:
                case GamepadEventType.ButtonUp:
                case GamepadEventType.ButtonPressed:
                {
                    var buttonIndex = bytes[2];
                    var value       = BitConverter.ToDouble(bytes, 3);
                    ProcessGamepadButtonEvent(gamepadEventType, (GamepadKeyCode)buttonIndex, value);
                }
                break;

                case GamepadEventType.Axis:
                {
                    var buttonIndex = bytes[2];
                    var x           = BitConverter.ToDouble(bytes, 3);
                    var y           = BitConverter.ToDouble(bytes, 11);
                    ProcessGamepadAxisEvent(x, y, (GamepadKeyCode)buttonIndex);
                }
                break;
                }
                UnityInputSystem.QueueStateEvent(RemoteGamepad, m_gamepadState);
            }
            break;
            }
        }