Skip to content

Instantly share code, notes, and snippets.

@arun02139
Created March 30, 2015 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun02139/d50fab7060b9404a1f92 to your computer and use it in GitHub Desktop.
Save arun02139/d50fab7060b9404a1f92 to your computer and use it in GitHub Desktop.
using UnityEngine;
using TouchScript;
using UnityEngine.EventSystems;
using System.Reflection;
public class TouchFilter : MonoBehaviour
{
void OnEnable()
{
TouchManager.Instance.TouchesBegan += touchEventOccured;
}
void OnDisable()
{
if(TouchManager.Instance != null)
TouchManager.Instance.TouchesBegan -= touchEventOccured;
}
void touchEventOccured(object sender, TouchEventArgs eventArgs)
{
ITouchManager gesture = sender as ITouchManager;
// to make sure this works for mouse input and touch-devices, starting from -1 (mouse) loop through
// each 'touch' in Input.touches and pass in the id to 'IsPointerOverEventSystemObject'
// LINK http://forum.unity3d.com/threads/ispointerovereventsystemobject-always-returns-false-on-mobile.265372/
for(int i=-1, il=Input.touches.Length; i<il; i++)
{
if (EventSystem.current.IsPointerOverGameObject(i))
{
foreach (ITouch touchPoint in eventArgs.Touches)
{
// hacking internals...
MethodInfo method = gesture.GetType().GetMethod("CancelTouch", BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(gesture, new object[] { touchPoint.Id });
}
return;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment