ソースコード
<summary>
</summary>
public static T2 FindClosestByLocalPosition<T1, T2>
(
this IReadOnlyList<T2> self,
T1 component,
float maxDistance
)
where T1 : Component
where T2 : Component
{
T2 closestComponent = null;
var closestDistance = Mathf.Infinity;
foreach ( var x in self )
{
var distance = Vector2.Distance
(
component.transform.localPosition,
x.transform.localPosition
);
if ( distance < closestDistance && distance < maxDistance )
{
closestDistance = distance;
closestComponent = x;
}
}
return closestComponent;
}