DaoNiaoShu_Dog/Assets/_Scripts/FrameworkYiLiao/Scroll/ScrollViewHorizontalDownMove.cs

67 lines
1.7 KiB
C#
Raw Normal View History

2025-09-08 14:51:28 +08:00
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ס
/// </summary>
public class ScrollViewHorizontalDownMove : MonoBehaviour
{
ScrollRect scrollRect; // <20><><EFBFBD><EFBFBD>ScrollView<65><77><EFBFBD><EFBFBD>
public float scrollSpeed = 0.5f; // <20><><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
private bool isScrollingLeft = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private bool isScrollingRight = false; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҹ<EFBFBD><D2B9><EFBFBD>
private void Start()
{
scrollRect = GetComponent<ScrollRect>();
}
// <20><><EFBFBD>鰴ť<E9B0B4>Ƿ񱻰<C7B7><F1B1BBB0>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>־
public void CheckLeftButton()
{
isScrollingLeft = true;
}
public void UncheckLeftButton()
{
isScrollingLeft = false;
}
public void CheckRightButton()
{
isScrollingRight = true;
}
public void UncheckRightButton()
{
isScrollingRight = false;
}
void Update()
{
// <20><><EFBFBD>ݰ<EFBFBD>ť<EFBFBD>İ<EFBFBD><C4B0><EFBFBD>״̬<D7B4><CCAC><EFBFBD>ƶ<EFBFBD>ScrollView
if (isScrollingLeft)
{
ScrollLeft();
}
else if (isScrollingRight)
{
ScrollRight();
}
}
// <20><><EFBFBD><EFBFBD>ScrollView<65><77><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
private void ScrollLeft()
{
float newPosition = scrollRect.horizontalNormalizedPosition - (scrollSpeed * Time.deltaTime);
newPosition = Mathf.Clamp(newPosition, 0f, 1f); // ȷ<><C8B7>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
scrollRect.horizontalNormalizedPosition = newPosition;
}
// <20><><EFBFBD><EFBFBD>ScrollView<65><77><EFBFBD>ұ<EFBFBD>
private void ScrollRight()
{
float newPosition = scrollRect.horizontalNormalizedPosition + (scrollSpeed * Time.deltaTime);
newPosition = Mathf.Clamp(newPosition, 0f, 1f); // ȷ<><C8B7>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>Χ<EFBFBD><CEA7>
scrollRect.horizontalNormalizedPosition = newPosition;
}
}