Bootstrap

Unity 无限循环滚动列表

Unity 无限滑动列表制作

Unity 无限滚动列表功能,效果,循环滚动,并且可以点击交互。
在这里插入图片描述
下面展示一些 内联代码片

public class SlideList : MonoBehaviour,IDragHandler
{
    public static SlideList Instance;
    public  List<RectTransform> itemDataArray = new List<RectTransform>();
    private List<Vector3> standardItemPosition = new List<Vector3>();
    private static float timer = 0;
    public float slideSpeed = 0.5f;
	private void Start()
	{
        Instance = this;

        foreach (RectTransform item in transform.Find("Content"))
		{
            itemDataArray.Add(item);
            standardItemPosition.Add(item.localPosition);
        }
	}

	public void HidScrollView()
    {
        this.gameObject.SetActive(false);
    }

    public void OnDrag(PointerEventData eventData)
    {
		
		if (Input.GetAxis("Mouse Y") < 0)
		{
            timer -= Input.GetAxis("Mouse Y") * slideSpeed;

			DownSlide(timer);

		}
		if (Input.GetAxis("Mouse Y") > 0)
		{
            timer += Input.GetAxis("Mouse Y") * slideSpeed;

			UPSlide(timer);
		}
	
	}
    private bool isSliderDown;

   
    public void UPSlide(float value)
    {

        for (int i = 0; i < itemDataArray.Count; i++)
        {
            if (i > 0)
            {
                value = Mathf.Clamp(value, 0, 1);
                itemDataArray[i].localPosition = Vector3.Lerp(standardItemPosition[i], standardItemPosition[i - 1], value);
            }

            else if (i == 0)
            {
                itemDataArray[i].localPosition = Vector3.Lerp(standardItemPosition[i], standardItemPosition[i] - new Vector3(0, -129, 0), value);
           
            }
        }
        if (value >= 1)
        {
            for (int i = 0; i < itemDataArray.Count - 1; i++)
            {
                RectTransform temp = itemDataArray[i];
                itemDataArray[i] = itemDataArray[i + 1];
                itemDataArray[i + 1] = temp;
            }
            timer = 0;
            itemDataArray[itemDataArray.Count - 1].localPosition = standardItemPosition[standardItemPosition.Count - 1];
        }
    }


    public void DownSlide(float value)
    {

        for (int i = itemDataArray.Count - 1; i >= 0; i--)
        {
            value = Mathf.Clamp(value, 0, 1);
            if (i < itemDataArray.Count - 1)
            {
                itemDataArray[i].localPosition = Vector3.Lerp(standardItemPosition[i], standardItemPosition[i + 1], value);
      
            }
            else if (i == itemDataArray.Count - 1)
            {
                itemDataArray[i].localPosition = Vector3.Lerp(standardItemPosition[i], standardItemPosition[i] + new Vector3(0, -129, 0), value);
            
            }

        }
        if (value >= 1)
        {
            itemDataArray[itemDataArray.Count - 1].localPosition = standardItemPosition[0];
            for (int i = itemDataArray.Count - 1; i > 0; i--)
            {

                RectTransform temp = itemDataArray[i];
                itemDataArray[i] = itemDataArray[i - 1];
                itemDataArray[i - 1] = temp;

            }
            timer = 0;
        }
    }

}

下面展示一些 内联代码片

public class Item :MonoBehaviour, IBeginDragHandler,IEndDragHandler,IDragHandler,IPointerDownHandler,IPointerUpHandler
{
	public bool isClick;

	public void OnBeginDrag(PointerEventData eventData)
	{
		isClick = false;
	}

	public void OnEndDrag(PointerEventData eventData)
	{
		
	}

	public void OnPointerDown(PointerEventData eventData)
	{
		isClick = true;
	}

	public void OnPointerUp(PointerEventData eventData)
	{
		if (isClick) {
			Debug.Log("点击:"+transform.GetComponentInChildren<Text>());
		}
	}

	void IDragHandler.OnDrag(PointerEventData eventData)
	{
		SlideList.Instance.OnDrag(eventData);

	}
}

工程链接,按需下载
https://download.csdn.net/download/qq_33547099/13799875

在这里插入图片描述

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;