From e5f19d6fef2894a9e897f4586034d2102976b49f Mon Sep 17 00:00:00 2001 From: NINI Date: Mon, 5 Oct 2026 05:21:19 +0900 Subject: [PATCH] Instrument Android composition input for native diagnosis --- .../MagnetismHeroes/UnityRuntime/Interaction/BoardInput.cs | 5 +++++ tools/android/send-composition-touch.ps1 | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Assets/MagnetismHeroes/UnityRuntime/Interaction/BoardInput.cs b/Assets/MagnetismHeroes/UnityRuntime/Interaction/BoardInput.cs index 9d42290..d9f9acd 100644 --- a/Assets/MagnetismHeroes/UnityRuntime/Interaction/BoardInput.cs +++ b/Assets/MagnetismHeroes/UnityRuntime/Interaction/BoardInput.cs @@ -33,6 +33,8 @@ namespace MagnetismHeroes.UnityRuntime.Interaction private float _pinchDistance; private int _fingerId = -1; private bool _waitForAllTouchesReleased; + private int _diagnosticEvents; + private bool _diagnosticReady; private int _pinchFirstId = -1, _pinchSecondId = -1; private readonly struct TouchContact { @@ -162,6 +164,7 @@ namespace MagnetismHeroes.UnityRuntime.Interaction private void RecordTouch(Finger finger) { + if (AcceptInput && _diagnosticEvents++ < 16) Debug.Log($"[CompositionInput] callback {finger.lastTouch.phase} screen={finger.screen?.name} current={Touchscreen.current?.name} gesture={_gesture}"); if (!AcceptInput || finger.screen != Touchscreen.current) return; // Copy each official history callback before later events overwrite the native touch slot. var touch = finger.lastTouch; @@ -228,6 +231,7 @@ namespace MagnetismHeroes.UnityRuntime.Interaction private void Update() { + if (AcceptInput && !_diagnosticReady) { _diagnosticReady = true; Debug.Log($"[CompositionInput] ready enabled={enabled} touchscreen={Touchscreen.current?.name} enhanced={EnhancedTouchSupport.enabled}"); } if (!AcceptInput) { _touchEvents.Clear(); _touches.Clear(); return; } bool hadTouches = _touchEvents.Count > 0, suppressRestOfFrame = false; while (_touchEvents.Count > 0) @@ -255,6 +259,7 @@ namespace MagnetismHeroes.UnityRuntime.Interaction } private void OnEnable() { + Debug.Log("[CompositionInput] subscribing"); EnhancedTouchSupport.Enable(); UnityEngine.InputSystem.EnhancedTouch.Touch.onFingerDown += RecordTouch; UnityEngine.InputSystem.EnhancedTouch.Touch.onFingerMove += RecordTouch; diff --git a/tools/android/send-composition-touch.ps1 b/tools/android/send-composition-touch.ps1 index d9cda23..0ae3bf1 100644 --- a/tools/android/send-composition-touch.ps1 +++ b/tools/android/send-composition-touch.ps1 @@ -12,8 +12,10 @@ function Varint([int]$Value) { } $message=[Collections.Generic.List[byte]]::new() for ($offset=0; $offset -lt $Contacts.Count; $offset+=4) { + # AVD touch injection uses portrait physical coordinates even when the app is landscape-left. + $fields=@(1080-$Contacts[$offset+1],$Contacts[$offset],$Contacts[$offset+2],$Contacts[$offset+3]) $touch=[Collections.Generic.List[byte]]::new() - for ($field=0; $field -lt 4; $field++) { $touch.Add([byte](8*($field+1))); $touch.AddRange([byte[]](Varint $Contacts[$offset+$field])) } + for ($field=0; $field -lt 4; $field++) { $touch.Add([byte](8*($field+1))); $touch.AddRange([byte[]](Varint $fields[$field])) } $message.Add(10); $message.AddRange([byte[]](Varint $touch.Count)); $message.AddRange($touch.ToArray()) } $frame=[byte[]]::new($message.Count+5); $frame[1]=($message.Count -shr 24) -band 255; $frame[2]=($message.Count -shr 16) -band 255