Ray getRay(Camera cam, Touch t) { Vector3 touchPoint = new Vector3(t.position.x, t.position.y, 0f); Ray targetRay = cam.ScreenPointToRay(touchPoint); return(targetRay); }
public bool AddTouch(Touch t, Camera castOn, Collider castAgainst) { Ray toCast = getRay(castOn, t); // Raycast the touch, see what we hit List <GestureHit> lh = innerCast(toCast, castAgainst); // Update the touch link with the found handlers MonoBehaviour[] allHanders = lh.SelectMany(m => m.HitHandlers).ToArray(); if (allHanders.Length == 0) { return(false); } touchLinks[t.fingerId] = allHanders; // Notify all handlers foreach (GestureHit gh in lh) { foreach (MonoBehaviour mb in gh.HitHandlers) { ((IGestureHandler)mb).AddTouch(t, gh.Hit, castOn); } } return(true); }
public void UpdateTouch(Touch t) { if (!touchLinks.ContainsKey(t.fingerId)) { return; } MonoBehaviour[] gestureHandlers = touchLinks[t.fingerId]; // Notify all enabled handlers foreach (MonoBehaviour h in gestureHandlers) { IGestureHandler handler = (IGestureHandler)h; handler.UpdateTouch(t); } }
public bool AddTouch(Touch t, Camera castOn, LayerMask hitLayers, bool DoRayCastAll, GUILayer gui) { Ray toCast = getRay(castOn, t); List <GestureHit> lh = null; // First see if we hit a GUI element if (gui != null) { lh = innerCastGUI(t.position, castOn, gui); } if (lh == null || lh.Count == 0) { // Raycast the touch, see what we hit if (DoRayCastAll) { lh = innerCastAll(toCast, hitLayers); } else { lh = innerCast(toCast, hitLayers); } } // Update the touch link with the found handlers MonoBehaviour[] allHanders = lh.SelectMany(m => m.HitHandlers).ToArray(); if (allHanders.Length == 0) { return(false); } touchLinks[t.fingerId] = allHanders; // Notify all handlers foreach (GestureHit gh in lh) { foreach (MonoBehaviour mb in gh.HitHandlers) { ((IGestureHandler)mb).AddTouch(t, gh.Hit, castOn); } } return(true); }
public bool AddTouch(Touch t, Camera castOn, LayerMask hitLayers, bool DoRayCastAll) { return(AddTouch(t, castOn, hitLayers, DoRayCastAll, null)); }