Skip to content
This repository was archived by the owner on Sep 7, 2022. It is now read-only.

Commit 9bc3f63

Browse files
authored
Merge pull request #272 from Unity-Technologies/siyaoH/1.17/combineTouch
cache RawTouch and dispatch during Input_Update
2 parents 12d2e94 + d87c64f commit 9bc3f63

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

com.unity.uiwidgets/Runtime/engine/UIWidgetsPanel.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void _convertPointerData(PointerEventData evt, out Vector2? position, out int po
493493
void Input_OnEnable() {
494494
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
495495
UnityEngine.UIWidgets.InitUIWidgets.Init();
496-
UnityEngine.UIWidgets.RawTouchEvent += ProcessRawTouch;
496+
UnityEngine.UIWidgets.RawTouchEvent += CacheRawTouch;
497497
#endif
498498
_inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch;
499499
}
@@ -507,6 +507,10 @@ enum TouchPhase {
507507
Canceled = 4
508508
}
509509

510+
void CacheRawTouch(UnityEngine.UIWidgets.RawTouchEventParam param) {
511+
rawTouchEventParams.Enqueue(param);
512+
}
513+
510514
void ProcessRawTouch(UnityEngine.UIWidgets.RawTouchEventParam param) {
511515
var position = _getPointerPosition(new Vector2(param.x, param.y));
512516
var pointerId = -1 - param.pointerId;
@@ -525,15 +529,23 @@ void ProcessRawTouch(UnityEngine.UIWidgets.RawTouchEventParam param) {
525529
break;
526530
}
527531
}
532+
533+
Queue<UnityEngine.UIWidgets.RawTouchEventParam> rawTouchEventParams =
534+
new Queue<UnityEngine.UIWidgets.RawTouchEventParam>();
528535
#endif
529536

530537
void Input_OnDisable() {
531-
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
532-
UnityEngine.UIWidgets.RawTouchEvent -= ProcessRawTouch;
538+
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
539+
UnityEngine.UIWidgets.RawTouchEvent -= CacheRawTouch;
533540
#endif
534541
}
535542

536543
void Input_Update() {
544+
#if !UNITY_EDITOR && (UNITY_IOS || UNITY_ANDROID)
545+
while (rawTouchEventParams.isNotEmpty()) {
546+
ProcessRawTouch(rawTouchEventParams.Dequeue());
547+
}
548+
#endif
537549
//we only process hover events for desktop applications
538550
if (_inputMode == UIWidgetsInputMode.Mouse) {
539551
if (_isEntered) {

0 commit comments

Comments
 (0)