|
|
|
|
|
|
WindowAdapter _windowAdapter; |
|
|
|
Texture _texture; |
|
|
|
Vector2 _lastMouseMove; |
|
|
|
bool _mouseEntered; |
|
|
|
|
|
|
|
HashSet<int> _enteredPointers; |
|
|
|
|
|
|
|
bool _mouseEntered { |
|
|
|
get { return !this._enteredPointers.isEmpty(); } |
|
|
|
} |
|
|
|
|
|
|
|
readonly ScrollInput _scrollInput = new ScrollInput(); |
|
|
|
DisplayMetrics _displayMetrics; |
|
|
|
|
|
|
protected override void OnEnable() { |
|
|
|
base.OnEnable(); |
|
|
|
|
|
|
|
//Disable touch -> mouse event on mobile devices
|
|
|
|
//Disable the default touch -> mouse event conversion on mobile devices
|
|
|
|
Input.simulateMouseWithTouches = false; |
|
|
|
|
|
|
|
this._displayMetrics = DisplayMetricsProvider.provider(); |
|
|
|
|
|
|
|
|
|
|
this._windowAdapter.attachRootWidget(root); |
|
|
|
this._lastMouseMove = Input.mousePosition; |
|
|
|
|
|
|
|
this._enteredPointers = new HashSet<int>(); |
|
|
|
} |
|
|
|
|
|
|
|
public float devicePixelRatio { |
|
|
|
|
|
|
this.unfocusIfNeeded(); |
|
|
|
} |
|
|
|
|
|
|
|
#if UNITY_IOS || UNITY_ANDROID
|
|
|
|
if (this._mouseEntered && Input.touchCount != 0) { |
|
|
|
this.handleTouchMove(); |
|
|
|
} |
|
|
|
#else
|
|
|
|
if (this._mouseEntered && (this._lastMouseMove.x != Input.mousePosition.x || |
|
|
|
this._lastMouseMove.y != Input.mousePosition.y)) { |
|
|
|
this.handleMouseMove(); |
|
|
|
if (this._mouseEntered) { |
|
|
|
if (this._lastMouseMove.x != Input.mousePosition.x || this._lastMouseMove.y != Input.mousePosition.y) { |
|
|
|
this.handleMouseMovement(); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
if (this._mouseEntered) { |
|
|
|
this.handleMouseScroll(); |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void handleTouchMove() { |
|
|
|
for (var touchIndex = 0; touchIndex < Input.touchCount; touchIndex++) { |
|
|
|
var touchEvent = Input.GetTouch(touchIndex); |
|
|
|
if (touchEvent.phase != TouchPhase.Moved) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
var pos = this.getPointPosition(touchEvent.position); |
|
|
|
this._windowAdapter.postPointerEvent(new PointerData( |
|
|
|
timeStamp: Timer.timespanSinceStartup, |
|
|
|
change: PointerChange.hover, |
|
|
|
kind: PointerDeviceKind.touch, |
|
|
|
device: InputUtils.getTouchFingerKey(touchEvent.fingerId), |
|
|
|
physicalX: pos.x, |
|
|
|
physicalY: pos.y |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void handleMouseMove() { |
|
|
|
void handleMouseMovement() { |
|
|
|
var pos = this.getPointPosition(Input.mousePosition); |
|
|
|
this._windowAdapter.postPointerEvent(new PointerData( |
|
|
|
timeStamp: Timer.timespanSinceStartup, |
|
|
|
|
|
|
this._windowAdapter.postPointerEvent(new PointerData( |
|
|
|
timeStamp: Timer.timespanSinceStartup, |
|
|
|
change: PointerChange.down, |
|
|
|
kind: InputUtils.getPointerDeviceKind(), |
|
|
|
kind: InputUtils.getPointerDeviceKind(eventData), |
|
|
|
device: InputUtils.getPointerDeviceKey(eventData), |
|
|
|
physicalX: position.x, |
|
|
|
physicalY: position.y |
|
|
|
|
|
|
this._windowAdapter.postPointerEvent(new PointerData( |
|
|
|
timeStamp: Timer.timespanSinceStartup, |
|
|
|
change: PointerChange.up, |
|
|
|
kind: InputUtils.getPointerDeviceKind(), |
|
|
|
kind: InputUtils.getPointerDeviceKind(eventData), |
|
|
|
device: InputUtils.getPointerDeviceKey(eventData), |
|
|
|
physicalX: position.x, |
|
|
|
physicalY: position.y |
|
|
|
|
|
|
this._windowAdapter.postPointerEvent(new PointerData( |
|
|
|
timeStamp: Timer.timespanSinceStartup, |
|
|
|
change: PointerChange.move, |
|
|
|
kind: InputUtils.getPointerDeviceKind(), |
|
|
|
kind: InputUtils.getPointerDeviceKind(eventData), |
|
|
|
device: InputUtils.getPointerDeviceKey(eventData), |
|
|
|
physicalX: position.x, |
|
|
|
physicalY: position.y |
|
|
|
|
|
|
public void OnPointerEnter(PointerEventData eventData) { |
|
|
|
this._mouseEntered = true; |
|
|
|
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|
|
|
this._enteredPointers.Add(pointerKey); |
|
|
|
|
|
|
|
kind: InputUtils.getPointerDeviceKind(), |
|
|
|
device: InputUtils.getPointerDeviceKey(eventData), |
|
|
|
kind: InputUtils.getPointerDeviceKind(eventData), |
|
|
|
device: pointerKey, |
|
|
|
physicalX: position.x, |
|
|
|
physicalY: position.y |
|
|
|
)); |
|
|
|
|
|
|
this._mouseEntered = false; |
|
|
|
var pointerKey = InputUtils.getPointerDeviceKey(eventData); |
|
|
|
this._enteredPointers.Remove(pointerKey); |
|
|
|
|
|
|
|
kind: InputUtils.getPointerDeviceKind(), |
|
|
|
device: InputUtils.getPointerDeviceKey(eventData), |
|
|
|
kind: InputUtils.getPointerDeviceKind(eventData), |
|
|
|
device: pointerKey, |
|
|
|
physicalX: position.x, |
|
|
|
physicalY: position.y |
|
|
|
)); |
|
|
|