// Creates the allocated Empty on initialization. static TouchData() { Empty = CreateEmpty(); }
// Casts a ray and returns the touchdata which the ray collided with. private bool TryGetTouchData(int fingerId, Vector3 position, Camera camera, LayerMask ignoreMask, out TouchData touchData) { if (TryRayCast(position, camera, ignoreMask, out RaycastHit hit)) { var collider = hit.collider; // @TODO: Fix this unwanted null error in stresstests if (collider == null) { touchData = TouchData.Empty; return(false); } // Fetch all the touch handlers. var downHandler = collider.GetComponent <ITouchDownHandler>(); var dragHandler = collider.GetComponent <ITouchDragHandler>(); var upHandler = collider.GetComponent <ITouchUpHandler>(); // If any handler is available, it will result in returning true and providing the TouchData through the "out". if (downHandler != null || dragHandler != null || upHandler != null) { // @TODO: Remove double null check for performance. downHandler?.OnDown(fingerId); touchData = new TouchData(collider, dragHandler, upHandler, position, Time.realtimeSinceStartup, fingerId); return(true); } else { _onMiss?.Invoke(); } } touchData = TouchData.Empty; return(false); }