Project_WL/Assets/Script/Util/ScrollRectAutoToggle.cs

28 lines
873 B
C#
Raw Normal View History

2025-02-14 06:31:33 +00:00
using UnityEngine;
using UnityEngine.UI;
public class ScrollRectAutoToggle : MonoBehaviour
{
ScrollRect scrollRect; // ScrollRect 참조
private void OnEnable()
{
AdjustScrollability();
}
void AdjustScrollability()
{
if (scrollRect == null) scrollRect = GetComponent<ScrollRect>();
if (scrollRect == null || scrollRect.content == null)
return;
RectTransform viewport = scrollRect.viewport; // ScrollRect의 Viewport
// Content의 크기가 Viewport보다 작거나 같으면 스크롤 불가능
bool canScrollHorizontally = scrollRect.content.rect.width > viewport.rect.width;
bool canScrollVertically = scrollRect.content.rect.height > viewport.rect.height;
scrollRect.horizontal = canScrollHorizontally;
scrollRect.vertical = canScrollVertically;
}
}