/// <summary> /// Get the nearest hovered picking targets. /// </summary> /// <param name="targets">The game objects to query for picking targets and test for hovered.</param> /// <param name="screenPosition">The position in camera screen space.</param> /// <param name="camera">The target camera to use for picking.</param> /// <param name="maxDistance">The maximum distance for a picking target to be considered hovered.</param> /// <param name="hit">Returns a single picking hit for the nearest hit.</param> /// <returns>Returns true if a picking target was within the maxDistance.</returns> public static bool GetHovered( IReadOnlyList <GameObject> targets, Vector2 screenPosition, Camera camera, float maxDistance, out PickingHit hit) { if (targets == null) { throw new ArgumentNullException(nameof(targets)); } if (camera == null) { throw new ArgumentNullException(nameof(camera)); } GetPickingTargets(targets, s_TargetsBuffer); return(GetHovered(s_TargetsBuffer, screenPosition, camera, maxDistance, out hit)); }
/// <summary> /// Get the nearest hovered picking targets. /// </summary> /// <param name="targets">The picking targets to test for hovered.</param> /// <param name="screenPosition">The position in camera screen space.</param> /// <param name="camera">The target camera to use for picking.</param> /// <param name="maxDistance">The maximum distance for a picking target to be considered hovered.</param> /// <param name="hit">Returns a single picking hit for the nearest hit.</param> /// <returns>Returns true if a picking target was within the maxDistance.</returns> public static bool GetHovered( IReadOnlyList <IPickingTarget> targets, Vector2 screenPosition, Camera camera, float maxDistance, out PickingHit hit) { if (targets == null) { throw new ArgumentNullException(nameof(targets)); } if (camera == null) { throw new ArgumentNullException(nameof(camera)); } if (!GetHoveredAll(targets, screenPosition, camera, maxDistance, s_HitsBuffer)) { hit = new PickingHit(null, float.MaxValue); return(false); } PickingHit closest = new PickingHit(null, float.MaxValue); foreach (var h in s_HitsBuffer) { if (h.distance < closest.distance) { closest = h; } } hit = closest; return(hit.valid); }