public class Test : MonoBehaviour
{
public int SelectIndex = 0;
public ScrollRect Scroll;
public ToggleGroup Group;
[ContextMenu("跳转")]
public void Test1()
{
Group.SetIndex(SelectIndex);
Scroll.MoveToIndex(Group.Count,SelectIndex);
}
}
扩展函数
public static void MoveToIndex(this ScrollRect scrollRect, int count, int index)
{
float normalizedPosition = (float)(index) / (count-1);
if (scrollRect.horizontal)
{
scrollRect.horizontalNormalizedPosition = normalizedPosition;
}
else
{
scrollRect.verticalNormalizedPosition = 1 - normalizedPosition;
}
}