Unity TouchScript 实时检测每个触摸点的移动距离

                

using System.Collections;
using System.Collections.Generic;
using TouchScript;
using TouchScript.Pointers;
using UnityEngine;

public class DangerTipMsg : MonoBehaviour
{
    public List<bool> OffsetTimerFirst = new List<bool>();

    private void OnEnable()
    {
        if (TouchManager.Instance != null)
        {
            TouchManager.Instance.PointersPressed += PointersPressedHandler;
            TouchManager.Instance.PointersUpdated += PointersUpdatedHandle;
        }

        for (int i = 0; i < 200; i++)
        {
            OffsetTimerFirst.Add(true);
        }
    }

    private void PointersPressedHandler(object sender, PointerEventArgs e)
    {

    }

    private void PointersUpdatedHandle(object sender, PointerEventArgs e)
    {
        foreach (var item in e.Pointers)
        {
            if (OffsetTimerFirst[item.Id])
            {
                OffsetTimerFirst[item.Id] = false;
                StartCoroutine(MoveLength(item));
            }
        }
    }


    // 多点触摸 每隔一秒 判断每个触摸点的移动距离
    IEnumerator MoveLength(Pointer p)
    {
        Vector3 v = p.Position;
        yield return new WaitForSeconds(1f);
        float length = Vector3.Distance(p.Position, v);
        OffsetTimerFirst[p.Id] = true;
        Debug.Log(length);
    }

    private void OnDisable()
    {
        if (TouchManager.Instance != null)
        {
            TouchManager.Instance.PointersPressed += PointersPressedHandler;
            TouchManager.Instance.PointersUpdated += PointersUpdatedHandle;
        }
    }
}

上一篇:单例模式


下一篇:Java OCR文字识别(Tess4J)