I've found out today that Unity's ScrollRect is behaving erratic when more than one touch is used for drag. I think that's a bug with UI. It jumps between fingers (to moving one), this script fixes it by blocking event data based on touch id.
parent
08c16817eb
commit
90a87e6e4d
|
@ -0,0 +1,45 @@
|
||||||
|
/// Credit Erdener Gonenc - @PixelEnvision
|
||||||
|
/*USAGE: Simply use that instead of the regular ScrollRect */
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
|
namespace UnityEngine.UI.Extensions
|
||||||
|
{
|
||||||
|
[AddComponentMenu ("UI/Extensions/ScrollRectMultiTouchFix")]
|
||||||
|
public class ScrollRectMultiTouchFix : ScrollRect
|
||||||
|
{
|
||||||
|
|
||||||
|
private int pid = -100;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Begin drag event
|
||||||
|
/// </summary>
|
||||||
|
public override void OnBeginDrag (UnityEngine.EventSystems.PointerEventData eventData)
|
||||||
|
{
|
||||||
|
pid = eventData.pointerId;
|
||||||
|
base.OnBeginDrag (eventData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Drag event
|
||||||
|
/// </summary>
|
||||||
|
public override void OnDrag (UnityEngine.EventSystems.PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (pid == eventData.pointerId)
|
||||||
|
base.OnDrag (eventData);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// End drag event
|
||||||
|
/// </summary>
|
||||||
|
public override void OnEndDrag (UnityEngine.EventSystems.PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (pid == eventData.pointerId) {
|
||||||
|
pid = -100;
|
||||||
|
base.OnEndDrag (eventData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue