#if UNITY_EDITOR using UnityEngine; using UnityEngine.UIElements; using System.Collections.Generic; namespace GSpawn { public static class ScrollViewEx { public static T findClosestOutOfBounds(this ScrollView scrollView, List items) where T : VisualElement { T closestItem = null; float minDist = float.MaxValue; Rect scrollViewRect = scrollView.localBound; var itemCorners = new List(); foreach(var item in items) { Rect itemRect = item.localBound; itemRect.calcCorners(itemCorners); if (!scrollViewRect.containsPoints(itemCorners)) { float d = (itemRect.center - scrollViewRect.center).magnitude; if (d < minDist) { minDist = d; closestItem = item; } } } return closestItem; } } } #endif