Unity-Technologies / UnityRenderStreaming

Streaming server for Unity
Other
1.31k stars 365 forks source link

[BUG]: cannot use touch scroll on UI #690

Open gawinwong opened 2 years ago

gawinwong commented 2 years ago

Package version

3.1.0-exp.3

Environment

* OS: Ubuntu 18.04
* Unity version: 2020.3.3
* Graphics API: Vulkan
* Browser: chrome 102.0.5005.61

Steps To Reproduce

  1. use broadcast sample
  2. add scroll view on canvas
  3. use webapp to receive render stream

Current Behavior

I can use mouse or wheel to scroll the the viewport, but cannot do that with touch slide on screen. I have found that this action will dispatch the event "touchmove", but cannot scroll the viewport. Whether it's the problem that Unity Input System doesn't support touch scroll or it's a bug of webapp?

Expected Behavior

No response

Anything else?

No response

gawinwong commented 2 years ago

Alright, it's because input system cannot process touch event. We can convert touch events to mouse events to scroll on UI. Hers is my solution, apply these changes to client/public/js/sender.js. And this can only use with one finger touch on screen.

_onTouchEvent(event) {
      // this.touchscreen.queueEvent(event, this.timeSinceStartup);
      // for (let touch of this.touchscreen.currentState.touchData) {
      //   this._queueStateEvent(touch, this.touchscreen);
      // }
    var touch = event.changedTouches[0];
    var simulatedEvent = new MouseEvent({
      touchstart: "mousedown",
      touchmove: "mousemove",
      touchend: "mouseup",
    }[event.type], {
      bubbles: true, cancelable: true, view: window, detail: 1, composed: true,
      screenX: touch.screenX, screenY: touch.screenY, clientX: touch.clientX, clientY: touch.clientY,
      ctrlKey: false, altKey: false, shiftKey: false, metaKey: false, button: 0, buttons: 1, relatedTarget: null
    });
    touch.target.dispatchEvent(simulatedEvent);
    if(event.type === "touchend") {
      // add this action to prevent jump back to previous position
      touch.target.dispatchEvent(new MouseEvent("mousedown", {}));
    }
  }
karasusan commented 2 years ago

memo: URS-454

kannan-xiao4 commented 2 years ago

@gawinwong Thanks reporting issue and suggestion for improvement. We will reproduce this issue and check InputSystem bug or WebApp implementation bug. If webapp implementation bug, we refer to your solution.