Prevent ghost clicks using finger interaction
This commit is contained in:
parent
48f5a48639
commit
a3a2732060
@ -528,18 +528,15 @@ namespace Passer {
|
||||
if (Camera.main == null || pointer.type != PointerType.Touch)
|
||||
return;
|
||||
|
||||
//if (eventSystem == null)
|
||||
// eventSystem = Object.FindObjectOfType<EventSystem>();
|
||||
//if (eventSystem == null)
|
||||
// return;
|
||||
|
||||
pointer.data.position = Camera.main.WorldToScreenPoint(pointer.pointerTransform.position);
|
||||
float distanceToPointer = Vector3.Distance(Camera.main.transform.position, pointer.pointerTransform.position);
|
||||
|
||||
System.Collections.Generic.List<RaycastResult> m_RaycastResultCache = new System.Collections.Generic.List<RaycastResult>();
|
||||
eventSystem.RaycastAll(pointer.data, m_RaycastResultCache);
|
||||
RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache);
|
||||
RaycastResult raycastResult = FindFirstRaycast(m_RaycastResultCache, distanceToPointer);
|
||||
m_RaycastResultCache.Clear();
|
||||
|
||||
|
||||
if (raycastResult.gameObject != null) {
|
||||
if (pointer.type == PointerType.Touch) {
|
||||
float distance = DistanceTipToTransform(pointer.pointerTransform, raycastResult.gameObject.transform);
|
||||
@ -559,9 +556,12 @@ namespace Passer {
|
||||
}
|
||||
}
|
||||
|
||||
private new RaycastResult FindFirstRaycast(System.Collections.Generic.List<RaycastResult> raycastResults) {
|
||||
private RaycastResult FindFirstRaycast(System.Collections.Generic.List<RaycastResult> raycastResults, float pointerDistance) {
|
||||
foreach (RaycastResult result in raycastResults) {
|
||||
if (result.isValid && result.worldPosition != Vector3.zero) {
|
||||
float resultDistance = Vector3.Distance(Camera.main.transform.position, result.worldPosition);
|
||||
if (result.isValid &&
|
||||
result.worldPosition != Vector3.zero &&
|
||||
Mathf.Abs(resultDistance - pointerDistance) < 0.02F) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -580,7 +580,6 @@ namespace Passer {
|
||||
}
|
||||
|
||||
private float DistanceTipToTransform(Transform fingerTip, Transform transform) {
|
||||
//Debug.DrawLine(fingerTip.position, transform.position);
|
||||
return (-transform.InverseTransformPoint(fingerTip.position).z * transform.lossyScale.z) - 0.01F;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user