예제 #1
0
    /// <summary>
    /// 注册点击处理
    /// </summary>
    /// <param name="handler">Handler.</param>
    public void AddScrollHandler(IScrollEvent handler)
    {
        if (handler == null)
        {
            return;
        }

        if (!_ScrollDelegates.Contains(handler))
        {
            _ScrollDelegates.Add(handler);
        }
    }
예제 #2
0
    /// <summary>
    /// 移除点击处理
    /// </summary>
    /// <param name="handler">Handler.</param>
    public void RemoveScrollHandler(IScrollEvent handler)
    {
        if (handler == null)
        {
            return;
        }

        if (_ScrollDelegates.Contains(handler))
        {
            _ScrollDelegates.Remove(handler);
        }
    }
        public void Init()
        {
            if (GetComponent <ScrollRect>() != null)
            {
                _scrollRect = GetComponent <ScrollRect>();
                _scrollRect.onValueChanged.AddListener(OnScroll);
                _scrollRect.movementType = ScrollRect.MovementType.Unrestricted;

                for (int i = 0; i < _scrollRect.content.childCount; i++)
                {
                    items.Add(_scrollRect.content.GetChild(i).GetComponent <RectTransform>());
                }

                if (_scrollRect.content.GetComponent <VerticalLayoutGroup>() != null)
                {
                    _verticalLayoutGroup = _scrollRect.content.GetComponent <VerticalLayoutGroup>();
                }

                if (_scrollRect.content.GetComponent <GridLayoutGroup>() != null)
                {
                    _gridLayoutGroup = _scrollRect.content.GetComponent <GridLayoutGroup>();
                }

                if (_scrollRect.content.GetComponent <ContentSizeFitter>() != null)
                {
                    _contentSizeFitter = _scrollRect.content.GetComponent <ContentSizeFitter>();
                }

                if (GetComponent <IScrollEvent>() != null)
                {
                    _scrollEvent = GetComponent <IScrollEvent>();
                }

                _isVertical = _scrollRect.vertical;
                _itemCount  = _scrollRect.content.childCount;
            }
            else
            {
                Debug.LogError("UI_InfiniteScroll => No ScrollRect component found");
            }
        }