قالب وردپرس درنا توس
Home / IOS Development / c # – Fix for ScrollRect multi-touch in Unity?

c # – Fix for ScrollRect multi-touch in Unity?



Currently, ScrollRect is extremely buggy when it comes to multi-touch on mobile devices.

If you try it out yourself, you will see that when you place two fingers on the screen, the content will jump around and produce some unexpected behavior.

Are there any solutions to this? Currently, this is the only solution I have found, but it is still buggy in some cases, and most importantly, does not determine the average input position (or MultiTouchPosition ) for all your fingers on the screen. 19659002] Here is my MultiTouchScrollRect.cs script UnityUIExtensions bitbucket, but it jumps every-time I place my next finger on the screen:

 using UnityEngine ;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class MultiTouchScrollRect: ScrollRect
{
    private int minimumTouchCount = 1
, maximumTouchCount = 2, pointerId = -100;     public Vector2 MultiTouchPosition     {         get         {             Vector2 position = Vector2.zero;             for (int i = 0; in <Input.touchCount && in <maximumTouchCount; i ++)             {                 position + = input.touches [i] position;             }             position / = ((Input.touchCount <= maximumTouchCount) ? Input.touchCount : maximumTouchCount); return position; } } public override void OnBeginDrag(PointerEventData eventData) { if (Input.touchCount > = minimumTouchCount)         {             pointerId = eventData.pointerId;             eventData.position = MultiTouchPosition;             base.OnBeginDrag (event data);         }     }     public override void OnDrag (PointerEventData eventData)     {         if (Input.touchCount> = minimumTouchCount)         {             eventData.position = MultiTouchPosition;             if (pointerId == eventData.pointerId)             {                 base.OnDrag (event data);             }         }     }     public override void OnEndDrag (PointerEventData eventData)     {         if (Input.touchCount> = minimumTouchCount)         {             pointerId = -100;             eventData.position = MultiTouchPosition;             base.OnEndDrag (event data);         }     } }

Thanks for your time!


Source link