Hi. I found that CapturePointer() method call makes that OnPointerXXX events are not called in runtime.
Here is code sample:
class WindowDragManipulator : PointerManipulator
{
private bool enabled;
private Vector2 startLayoutPosition;
private Vector3 startPointerPosition;
protected override void RegisterCallbacksOnTarget()
{
this.target.RegisterCallback<PointerDownEvent>(OnPointerDown);
this.target.RegisterCallback<PointerMoveEvent>(OnPointerMove);
this.target.RegisterCallback<PointerUpEvent>(OnPointerUp);
}
protected override void UnregisterCallbacksFromTarget()
{
this.target.UnregisterCallback<PointerDownEvent>(OnPointerDown);
this.target.UnregisterCallback<PointerMoveEvent>(OnPointerMove);
this.target.UnregisterCallback<PointerUpEvent>(OnPointerUp);
}
private void OnPointerDown(PointerDownEvent e)
{
if (this.enabled)
{
e.StopImmediatePropagation();
return;
}
this.startLayoutPosition = this.target.layout.position;
this.startPointerPosition = e.position;
this.target.CapturePointer(e.pointerId);
e.StopPropagation();
this.enabled = true;
}
private void OnPointerMove(PointerMoveEvent e)
{
if (!this.enabled || !this.target.HasPointerCapture(e.pointerId))
{
return;
}
var pointerDelta = e.position - this.startPointerPosition;
var margin = this.target.layout.size * 0.5f;
this.target.style.left = Mathf.Clamp(this.startLayoutPosition.x + pointerDelta.x, -margin.x, this.target.panel.visualTree.worldBound.width - margin.x);
this.target.style.top = Mathf.Clamp(this.startLayoutPosition.y + pointerDelta.y, -margin.y, this.target.panel.visualTree.worldBound.height - margin.y);
e.StopPropagation();
}
private void OnPointerUp(PointerUpEvent e)
{
if (!this.enabled || !this.target.HasPointerCapture(e.pointerId))
{
return;
}
this.target.ReleasePointer(e.pointerId);
e.StopPropagation();
this.enabled = false;
}
}
This works perfectly with 1.0.0-preview.14, but not work for preview.16.