元素高度可变 无限滚动列表

本文介绍如何处理元素高度可变的无限滚动列表,并在拖动操作中避免响应列表元素的点击事件。关键在于实现IBeginDragHandler, IDragHandler, IEndDragHandler接口。" 122059211,11323583,阿里云Blink产品详解,"['云计算', 'big data', '实时计算']
摘要由CSDN通过智能技术生成

必须继承 IBeginDragHandler, IDragHandler, IEndDragHandler 这几个接口,否则拖动的时候会响应列表元素的点击 事件。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using SimpleJSON;
using YanhuaMMO;
public class DynamicHeightList : MonoBehaviour , IBeginDragHandler, IDragHandler, IEndDragHandler
{

    public Vector2 minCellSize;

    public int maxRowCount = 5;

    public int columeCount = 1;//列数

    public Vector2 spaceSize;

    private List<DynamicInfinityItem> itemList;

    public GameObject renderGo;

    protected IList mDataProviders;

    private Vector2 lastDownMousePos;

    private bool isMouseDown = false;

    public int elasticDist = 25;

    private int validCount = 0;

    private float viewheight;

    private float zuni = 0.95f;

    private Coroutine guanxingCo;

    private List<DynamicInfinityItem> allItemRenders;

    private Vector3 startDownPos;

    // Use this for initialization
    void Start () {
       
        viewheight = gameObject.GetComponent<RectTransform>().sizeDelta.y;

        itemList = new List<DynamicInfinityItem>();
        //validCount = Mathf.Min(mDataProviders.Count, maxRowCount * columeCount);

        initItem();
       // updateValidItem();

        //AddTriggersListener(gameObject, EventTriggerType.PointerDown, startDrag);
        //AddTriggersListener(gameObject, EventTriggerType.PointerUp, stopDrag);

    }

    public void OnBeginDrag(PointerEventData eventData)
    {
        startDrag(eventData);
    }

    public void OnEndDrag(PointerEventData eventData)
    {
        stopDrag(eventData);
    }

    public void OnDrag(PointerEventData eventData)
    {

    }

    public void setDataByJsonArray(string dataarr)
    {
        JSONArray dataList = JSON.Parse(dataarr).AsArray;
        List<JSONNode> dataNode = new List<JSONNode>();
        for (int i = 0; i < dataList.Count; i++)
            dataNode.Add(dataList[i]);
        setDataProvider(dataNode);
    }
    public void setDataProvider(IList dataprovider)
    {
        StopAllCoroutines();
        mDataProviders = dataprovider;
        validCount = Mathf.Min(mDataProviders.Count, maxRowCount * columeCount);

        updateValidItem();
        if (itemList.Count == 0)
            return;
        itemList[0].transform.localPosition = new Vector3(0, 0, 0);
        updateItemPos();
    }
    private void startDrag(BaseEventData data)
    {
        isMouseDown = true;
        if (itemList.Count == 0)
            return;

        lastDownMousePos = Input.mousePosition;
        startDownPos = Input.mousePosition;
        if (guanxingCo != null)
            StopCoroutine(guanxingCo);
        StopAllCoroutines();
        StartCoroutine(moveContent());
    }

    private void stopDrag(BaseEventData data)
    {
        isMouseDown = false;

        if (itemList.Count ==  0)
            return;
        if (itemList[0].itemIndex == 0 && itemList[0].transform.localPosition.y < 0)
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值