public void OnTouch(TouchPoint touch) { int fingerID = touch.GetID(); EventBase.Type gesture = touch.GetGesture(); Ray touchRay = touch.GetRay(); // Check if the ray from the main camera touch intersects with a collider or rigidbody // and determine if the ray intersects this object RaycastHit rayCast; if (Physics.Raycast(touchRay.origin, touchRay.direction, out rayCast) && rayCast.transform.gameObject == gameObject) { isTouched = true; } else { isTouched = false; } switch (gesture) { case (EventBase.Type.Down): // Add finger to list if (isTouched) { if (touchlist.Contains(fingerID)) { Debug.Log("Warning: Touch down detected for existing touch - should not happen"); } touchlist[fingerID] = touch; OnTouchDown(touch); } break; case (EventBase.Type.Move): if (isTouched) { touchlist[fingerID] = touch; OnTouchMove(touch); } else if (touchlist.Contains(fingerID)) { touchlist.Remove(fingerID); OnTouchUp(touch); } break; case (EventBase.Type.Up): if (touchlist.Contains(fingerID)) { touchlist.Remove(fingerID); OnTouchUp(touch); } isTouched = false; break; } }
public void OnEvent(TouchPoint touchPoint) { Vector3 screenPosition = RawTouchPosToCanvasCoords(touchPoint.GetPosition()); int touchID = touchPoint.GetID(); //Debug.Log(touchPoint.GetPosition() + " " + touchPoint.GetID() + " " + touchPoint.GetGesture()); if (!touchList.ContainsKey(touchID)) { if (touchPoint.GetGesture() == EventBase.Type.Down) { GameObject visualMarker = Instantiate(touchPointPrefab); visualMarker.name = "TouchPoint " + touchID; visualMarker.transform.SetParent(transform); // Update position with new touch data visualMarker.transform.position = screenPosition; visualMarker.transform.localScale = Vector3.one * 10; touchPoint.SetObjectTouched(visualMarker); touchPoint.Update(screenPosition, EventBase.Type.Down); touchList.Add(touchID, touchPoint); } } else { if (touchPoint.GetGesture() == EventBase.Type.Move) { // Get the existing touch data TouchPoint existingTouchPoint = (TouchPoint)touchList[touchID]; GameObject visualMarker = existingTouchPoint.GetObjectTouched(); // Update position with new touch data visualMarker.transform.position = RawTouchPosToCanvasCoords(touchPoint.GetPosition()); visualMarker.transform.localScale = Vector3.one * 10; existingTouchPoint.Update(screenPosition, EventBase.Type.Move); touchList[touchID] = existingTouchPoint; } else if (touchPoint.GetGesture() == EventBase.Type.Up) { // Get the existing touch data TouchPoint existingTouchPoint = (TouchPoint)touchList[touchID]; GameObject visualMarker = existingTouchPoint.GetObjectTouched(); existingTouchPoint.Update(screenPosition, EventBase.Type.Up); // Remove the TouchPoint Destroy(visualMarker); touchList.Remove(touchID); } } }