using UnityEngine;
using UnityEngine.UIElements;
[UxmlElement]
public partial class TestPointerId : VisualElement
{
public TestPointerId()
{
var A = new VisualElement { name = "A" };
var B = new VisualElement { name = "B" };
A.style.width = A.style.height = 200;
A.style.backgroundColor = Color.red;
B.style.width = B.style.height = 200;
B.style.backgroundColor = Color.blue;
B.style.left = 250;
this.Add(A);
this.Add(B);
// events
A.RegisterCallback<PointerDownEvent>(evt =>
{
Debug.Log($"A capturing pointer {evt.pointerId}.");
A.CapturePointer(evt.pointerId);
});
A.RegisterCallback<PointerUpEvent>(evt =>
{
if (A.HasPointerCapture(evt.pointerId))
{
Debug.Log($"A released pointer {evt.pointerId}.");
A.ReleasePointer(evt.pointerId);
}
});
B.RegisterCallback<PointerDownEvent>(evt =>
{
Debug.Log($"B capturing pointer {evt.pointerId}.");
B.CapturePointer(evt.pointerId);
});
B.RegisterCallback<PointerUpEvent>(evt =>
{
if (B.HasPointerCapture(evt.pointerId))
{
Debug.Log($"B released pointer {evt.pointerId}.");
B.ReleasePointer(evt.pointerId);
}
});
}
}
This is a custom VisualElement. When running on an Android device, first press on A without releasing, and then press another finger on B.
The normal Log output should be:
A capturing pointer 1.
B capturing pointer 2.
But the output on the device is:
A capturing pointer 1.
A capturing pointer 1.
What is the reason for this?
I am using Unity 6, and the input system is Input Manager (Old).
Thanks.
Update:
When selecting Input System Package (new) or Both, log is correct. Only when selecting Input Manager (Old), log is wrong. This may be a bug in Unity.