private static TouchPhase ToInputSystem(SimulatorTouchPhase original) { switch (original) { case SimulatorTouchPhase.None: return(TouchPhase.None); case SimulatorTouchPhase.Began: return(TouchPhase.Began); case SimulatorTouchPhase.Moved: return(TouchPhase.Moved); case SimulatorTouchPhase.Ended: return(TouchPhase.Ended); case SimulatorTouchPhase.Canceled: return(TouchPhase.Canceled); case SimulatorTouchPhase.Stationary: return(TouchPhase.Stationary); default: throw new ArgumentOutOfRangeException(nameof(original), original, "Unexpected value"); } }
public void Touch(int id, Vector2 position, SimulatorTouchPhase phase) { // Input.SimulateTouch expects a single event each frame and if sent two like Moved then Ended will create a separate touch. // So we delay calling Input.SimulateTouch until update. var newPhase = ToLegacy(phase); if (Time.frameCount == m_LastEventFrame) { if (m_NextPhase == TouchPhase.Began) { return; } else if (m_NextPhase == TouchPhase.Moved && newPhase == TouchPhase.Ended) { m_NextPhase = TouchPhase.Ended; m_NextPosition = position; } } else { m_NextPosition = position; m_NextPhase = newPhase; m_NextId = id; m_LastEventFrame = Time.frameCount; } }
public void Touch(int id, Vector2 position, SimulatorTouchPhase phase) { // Input System does not accept 0 as id id++; var screen = Touchscreen.current; if (screen == null) { return; } InputSystem.QueueStateEvent(screen, new TouchState { touchId = id, phase = ToInputSystem(phase), position = position }); }
private static TouchPhase ToLegacy(SimulatorTouchPhase original) { switch (original) { case SimulatorTouchPhase.Began: return(TouchPhase.Began); case SimulatorTouchPhase.Moved: return(TouchPhase.Moved); case SimulatorTouchPhase.Ended: return(TouchPhase.Ended); case SimulatorTouchPhase.Canceled: return(TouchPhase.Canceled); case SimulatorTouchPhase.Stationary: return(TouchPhase.Stationary); default: throw new ArgumentOutOfRangeException(nameof(original), original, "None is not a supported phase with legacy input system"); } }
public void Touch(int id, Vector2 position, SimulatorTouchPhase phase) { Input.SimulateTouch(id, position, ToLegacy(phase)); }