Hi, Unity Team:
SomeTimes It Missed Touch Began Phase.
In Other words, It Skips Touch.Began Phase to Touch.Moved Phase.
Thanks.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
using TouchPhase = UnityEngine.InputSystem.TouchPhase;
public class testTouch : MonoBehaviour
{
HashSet<int> hasBegenToucheIDs = new HashSet<int>();
HashSet<int> hasMissedBegenToucheIDs = new HashSet<int>();
private void OnEnable()
{
#if UNITY_EDITOR
TouchSimulation.Enable();
#endif
EnhancedTouchSupport.Enable();
}
// Update is called once per frame
void Update()
{
var touches = Touch.activeTouches;
bool hasBegan = false;
foreach (var touch in touches)
{
if (touch.phase == TouchPhase.Began)
{
hasBegan = true;
hasBegenToucheIDs.Add(touch.touchId);
}
}
if (hasBegan)
{
var sb = new StringBuilder();
sb.AppendFormat("[{0}]\thasBegan\t", Time.frameCount);
foreach (var touch in touches)
{
sb.AppendFormat("ID:{0}, Phase:{1}", touch.touchId, touch.phase);
}
Debug.Log(sb.ToString());
}
else
{
bool hasMissedBegan = false;
foreach (var touch in touches)
{
var touchId = touch.touchId;
if (!hasBegenToucheIDs.Contains(touchId) && !hasMissedBegenToucheIDs.Contains(touchId))
{
hasMissedBegan = true;
break;
}
}
if (hasMissedBegan)
{
var sb = new StringBuilder();
sb.AppendFormat("[{0}]\tmissedBegan\t", Time.frameCount);
foreach (var touch in touches)
{
var touchId = touch.touchId;
if (!hasBegenToucheIDs.Contains(touchId) && !hasMissedBegenToucheIDs.Contains(touchId))
{
hasMissedBegenToucheIDs.Add(touchId);
sb.AppendFormat("ID:{0}, Phase:{1}", touch.touchId, touch.phase);
}
}
Debug.Log(sb.ToString());
}
}
}
}