Created
March 30, 2015 06:15
-
-
Save arun02139/d50fab7060b9404a1f92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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