循环下拉

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using DG.Tweening;

namespace QK.QKComponent
{
    public class ExpandTipsCircularScrollView : UICircularScrollView
    {
        // public GameObject m_ExpandTips;
        public GameObject m_Arrow;
        public float m_TipsSpacing;
        public bool m_bEnableClick = true;
        public bool OutRangeCheck = true;
        /// <summary>
        /// 是否需要水平滑动翻页
        /// </summary>
        public bool isSliderHor=false;
        private int __index;
        /// <summary>
        /// 是否滑动
        /// </summary>
        private bool isDrag;
        /// <summary>
        /// 水平翻页阀值
        /// </summary>
        private int __horValue=50;

        private int m_currCenterIndex = 0;

        private float m_ExpandTipsHeight;
        private bool m_IsExpand = false;
        private float m_DragStartPos;
        public ScrollRect ScrollRectView
        {
            get
            {
                return m_ScrollRect;
            }
        }
        public override void Init(Action<GameObject, int> callBack, Action<GameObject, int> onClickCallBack)
        {
            base.Init(callBack, onClickCallBack);

            //m_ExpandTips.SetActive(false);
            // UIUtils.SetActive(m_ExpandTips, false);
            //
            // var rectTrans = m_ExpandTips.GetComponent<RectTransform>();
            // rectTrans.pivot = new Vector2(0, 1);
            // rectTrans.anchorMin = new Vector2(0, 1);
            // rectTrans.anchorMax = new Vector2(0, 1);
            // rectTrans.anchoredPosition = new Vector2(0, 0);
            // rectTrans.sizeDelta = new Vector2(m_ContentWidth, rectTrans.sizeDelta.y);
            //
            // m_ExpandTipsHeight = m_ExpandTips.GetComponent<RectTransform>().rect.height;

           if( m_Arrow != null)
            {
                var arrowRectTrams = m_Arrow.GetComponent<RectTransform>();
                arrowRectTrams.pivot = new Vector2(0.5f, 0.5f);
                arrowRectTrams.anchorMin = new Vector2(0, 0.5f);
                arrowRectTrams.anchorMax = new Vector2(0, 0.5f);
            }
        }

        public override void ShowList(int num)
        {
            base.ShowList(num);

            m_IsExpand = false;
            m_IsClearList = true;
            lastClickCellName = null;
            // UIUtils.SetActive(m_ExpandTips, false);
            //m_ExpandTips.SetActive(false);

            if (isSliderHor) 
            {
                //__index = 2;
                //m_currCenterIndex = 0;
            }
        }

        public void JumpToTop()
        {
            if (m_Direction == e_Direction.Horizontal)
            {
                m_ScrollRect.horizontalNormalizedPosition = 1;
            }
            else if (m_Direction == e_Direction.Vertical)
            {
                m_ScrollRect.verticalNormalizedPosition = 1;
            }
        }
        public void JumpToBottom()
        {
            if (m_Direction == e_Direction.Horizontal)
            {
                m_ScrollRect.horizontalNormalizedPosition = 0;
            }
            else if (m_Direction == e_Direction.Vertical)
            {
                m_ScrollRect.verticalNormalizedPosition = 0;
            }
        }

        private string lastClickCellName = null;
        public override void OnClickCell(GameObject cell)
        {
            // Debuger.Log(cell.gameObject.name);
            // if(lastClickCellName == null || cell.name == lastClickCellName || !m_IsExpand)
            // {
            //     m_IsExpand = !m_IsExpand;
            // }
            // lastClickCellName = cell.name;
            //
            // float index = float.Parse(cell.name);
            //
            // int curRow = Mathf.FloorToInt(index / m_Row) + 1;
            //
            // //-> Tips框 显示
            // //m_ExpandTips.SetActive(m_IsExpand);
            // UIUtils.SetActive(m_ExpandTips, m_IsExpand);
            // m_ExpandTips.transform.localPosition = new Vector3(0, -((m_Spacing + m_CellObjectHeight) * curRow + m_TipsSpacing), 0);
            //
            // //-> Content尺寸 计算
            // float contentHeight = m_IsExpand ? m_ContentHeight + m_ExpandTipsHeight + m_TipsSpacing : m_ContentHeight;
            // contentHeight = contentHeight < m_PlaneHeight ? m_PlaneHeight : contentHeight;
            // m_ContentRectTrans.sizeDelta = new Vector2(m_ContentWidth, contentHeight);
            //
            // m_MinIndex = -1;
            //
            // for(int i = 0, length = m_CellInfos.Length ; i < length; i++)
            // {
            //     CellInfo cellInfo = m_CellInfos[i];
            //
            //     float pos = 0;  // Y 坐标
            //     float rowPos = 0; //计算每排里面的cell 坐标
            //
            //     pos = m_CellObjectHeight * Mathf.FloorToInt(i / m_Row) + m_Spacing * (Mathf.FloorToInt(i / m_Row) + 1);
            //     rowPos = m_CellObjectWidth * (i % m_Row) + m_Spacing * (i % m_Row);
            //
            //     pos += (i/m_Row >= curRow && m_IsExpand) ? m_ExpandTipsHeight + m_TipsSpacing*2 - m_Spacing : 0; //往下移 Tips框高 和 距离
            //
            //     cellInfo.pos = new Vector3(rowPos, -pos, 0);
            //
            //     if(IsOutRange(-pos))
            //     {
            //         if(cellInfo.obj != null)
            //         {
            //             SetPoolsObj(cellInfo.obj);
            //             cellInfo.obj = null;
            //         }
            //     }
            //     else
            //     {
            //         //-> 记录显示范围中的 首位index 和 末尾index
            //         m_MinIndex = m_MinIndex == -1 ? i : m_MinIndex;// 首位 Index
            //         m_MaxIndex = i; // 末尾 Index
            //
            //         GameObject cellObj = cellInfo.obj == null ? GetPoolsObj() : cellInfo.obj;
            //         cellObj.GetComponent<RectTransform>().anchoredPosition = cellInfo.pos;
            //         cellInfo.obj = cellObj;
            //     }
            //
            //     m_CellInfos[i] = cellInfo;
            // }
            //
            // if (m_Arrow != null)
            // {
            //     var arrowObj = m_Arrow.transform.GetComponent<RectTransform>();
            //     arrowObj.anchoredPosition = new Vector2(cell.transform.localPosition.x + (m_CellObjectWidth / 2), arrowObj.anchoredPosition.y);
            // }
            Func(m_FuncOnClickCallBack, cell);
        }

        public int GetContentRow()
        {
            Rect planeRect = GetComponent<RectTransform>().rect;
            return Mathf.CeilToInt(Mathf.Abs(planeRect.height) / (m_CellObjectHeight + m_Y_Spacing));
        }

        private Dictionary<GameObject, bool> isAddedListener = new Dictionary<GameObject, bool>();
        protected override GameObject GetPoolsObj()
        {
            GameObject cell = base.GetPoolsObj();
            
            if (m_bEnableClick && !isAddedListener.ContainsKey(cell))
            {
                //Button button = cell.GetComponent<Button>() == null ? cell.AddComponent<Button>() : cell.GetComponent<Button>();

                //button.onClick.AddListener(delegate () { OnClickCell(cell); });

                ButtonScaler button = cell.GetComponent<ButtonScaler>() == null ? cell.AddComponent<ButtonScaler>() : cell.GetComponent<ButtonScaler>();
                button.baseScrollRect = m_ScrollRect;
                button.onClick = delegate { OnClickCell(cell); };

                isAddedListener[cell] = true;
            }

            return cell;
        }

        protected override bool IsOutRange(float pos)
        {
            bool ret = OutRangeCheck && base.IsOutRange(pos);
            //Vector3 listP = m_ContentRectTrans.anchoredPosition;
            //if (m_Direction == e_Direction.Vertical)
            //{
            //    if (pos + listP.y > m_CellObjectHeight || pos + listP.y < -rectTrans.rect.height)
            //    {
            //        return true;
            //    }
            //}
            return ret;
        }

        /// <summary>
        /// 得到当前现实的UI索引
        /// </summary>
        /// <param name="index"></param>
        /// <param name="pos"></param>
        protected override void SelfUpdateCheck(int index, float pos)
        {
            if (isSliderHor && m_Direction == e_Direction.Horizontal)
            {
                float start = pos + m_ContentRectTrans.anchoredPosition.x - m_X_Spacing;
                float end = start + m_CellObjectWidth;
                float center = rectTrans.rect.width / 2;
                //this.index = index;
                //if (start < center && center < end)
                //    m_currCenterIndex = index;
                if (start < center && center < end&& !isDrag)
                    __index = index;
                //int total = m_CellInfos.Length;
                //if (index == total - 1)
                //    OnCenterCellChange(m_currCenterIndex, total);
            }
        }
        public override void OnBeginDrag(PointerEventData eventData)
        {
            isDrag = true;
            m_DragStartPos = m_Content.GetComponent<RectTransform>().anchoredPosition.x;
            //Debug.LogError("开始:" + m_DragStartPos);
        }
        /// <summary>
        /// 鼠标滑动停止 开始移动
        /// </summary>
        /// <param name="eventData"></param>
        public override void OnEndDrag(PointerEventData eventData)
        {
            isDrag = false;
            if (isSliderHor && m_Direction == e_Direction.Horizontal)
            {
                float deltaPos = m_DragStartPos - m_Content.GetComponent<RectTransform>().anchoredPosition.x;
                //Debug.LogError("结束:" + deltaPos);
                //Debug.LogError(index);
                if (deltaPos > __horValue)
                {
                    m_currCenterIndex = __index + 1;
                    if (m_currCenterIndex> m_CellInfos.Length - 1)
                    {
                        m_currCenterIndex = m_CellInfos.Length - 1;
                    }
                }
                else if (deltaPos < -__horValue)
                {
                    m_currCenterIndex = __index - 1;
                    if (m_currCenterIndex < 0)
                    {
                        m_currCenterIndex = 0;
                    }
                }

                int totalDec = m_CellInfos.Length - 1;
                float target = (1f / totalDec) * m_currCenterIndex;
                DOTween.To(x => m_ScrollRect.horizontalNormalizedPosition = x, m_ScrollRect.horizontalNormalizedPosition, target, 0.25f);
            }
        }
    }
}

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace QK.QKComponent
{
    public enum e_Direction
    {
        Horizontal,
        Vertical
    }

    public class UICircularScrollView : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
    {
        public GameObject m_PointingFirstArrow;
        public GameObject m_PointingEndArrow;

        public e_Direction m_Direction = e_Direction.Horizontal;
        public bool m_IsShowArrow = true;

        public int m_Row = 1;

        public float m_X_Spacing = 0f; //间距
        public float m_Y_Spacing = 0f; //间距
        public GameObject m_CellGameObject; //指定的cell

        protected Action<GameObject, int> m_FuncCallBackFunc;
        protected Action<GameObject, int> m_FuncOnClickCallBack;
        protected Action<int, bool, GameObject> m_FuncOnButtonClickCallBack;

        protected RectTransform rectTrans;

        protected float m_PlaneWidth;
        protected float m_PlaneHeight;

        protected float m_ContentWidth;
        protected float m_ContentHeight;

        protected float m_CellObjectWidth;
        protected float m_CellObjectHeight;

        protected GameObject m_Content;
        protected RectTransform m_ContentRectTrans;

        private bool m_isInited = false;

        //记录 物体的坐标 和 物体 
        protected struct CellInfo
        {
            public Vector3 pos;
            public GameObject obj;
        };
        protected CellInfo[] m_CellInfos;

        protected bool m_IsInited = false;

        protected ScrollRect m_ScrollRect;

        protected int m_MaxCount = -1; //列表数量

        protected int m_MinIndex = -1;
        protected int m_MaxIndex = -1;

        protected bool m_IsClearList = false; //是否清空列表

        public virtual void Init(Action<GameObject, int> callBack)
        {
            Init(callBack, null);
        }
        public virtual void Init(Action<GameObject, int> callBack, Action<GameObject, int> onClickCallBack, Action<int, bool, GameObject> onButtonClickCallBack)
        {
            if (onButtonClickCallBack != null)
            {
                m_FuncOnButtonClickCallBack = onButtonClickCallBack;
            }
            Init(callBack, onClickCallBack);
        }
        public virtual void Init(Action<GameObject, int> callBack, Action<GameObject, int> onClickCallBack)
        {

            DisposeAll();

            m_FuncCallBackFunc = callBack;

            if (onClickCallBack != null)
            {
                m_FuncOnClickCallBack = onClickCallBack;
            }

            if (m_isInited)
                return;


            m_Content = this.GetComponent<ScrollRect>().content.gameObject;

            if (m_CellGameObject == null)
            {
                m_CellGameObject = m_Content.transform.GetChild(0).gameObject;
            }
            /* Cell 处理 */
            //m_CellGameObject.transform.SetParent(m_Content.transform.parent, false);
            SetPoolsObj(m_CellGameObject);

            RectTransform cellRectTrans = m_CellGameObject.GetComponent<RectTransform>();
            cellRectTrans.pivot = new Vector2(0.5f, 0.5f);
            CheckAnchor(cellRectTrans);
            cellRectTrans.anchoredPosition = Vector2.zero;

            //记录 Cell 信息
            m_CellObjectHeight = cellRectTrans.rect.height;
            m_CellObjectWidth = cellRectTrans.rect.width;

            //记录 Plane 信息
            rectTrans = GetComponent<RectTransform>();
            Rect planeRect = rectTrans.rect;
            m_PlaneHeight = planeRect.height;
            m_PlaneWidth = planeRect.width;

            //记录 Content 信息
            m_ContentRectTrans = m_Content.GetComponent<RectTransform>();
            Rect contentRect = m_ContentRectTrans.rect;
            m_ContentHeight = contentRect.height;
            m_ContentWidth = contentRect.width;

            m_ContentRectTrans.pivot = new Vector2(0f, 1f);
            //m_ContentRectTrans.sizeDelta = new Vector2 (planeRect.width, planeRect.height);
            //m_ContentRectTrans.anchoredPosition = Vector2.zero;
            CheckAnchor(m_ContentRectTrans);

            m_ScrollRect = this.GetComponent<ScrollRect>();

            m_ScrollRect.onValueChanged.RemoveAllListeners();
            //添加滑动事件
            m_ScrollRect.onValueChanged.AddListener(delegate (Vector2 value) { ScrollRectListener(value); });

            if (m_PointingFirstArrow != null || m_PointingEndArrow != null)
            {
                m_ScrollRect.onValueChanged.AddListener(delegate (Vector2 value) { OnDragListener(value); });
                OnDragListener(Vector2.zero);
            }

            //InitScrollBarGameObject(); // 废弃

            m_isInited = true;

        }
        //检查 Anchor 是否正确
        private void CheckAnchor(RectTransform rectTrans)
        {
            if (m_Direction == e_Direction.Vertical)
            {
                if (!((rectTrans.anchorMin == new Vector2(0, 1) && rectTrans.anchorMax == new Vector2(0, 1)) ||
                         (rectTrans.anchorMin == new Vector2(0, 1) && rectTrans.anchorMax == new Vector2(1, 1))))
                {
                    rectTrans.anchorMin = new Vector2(0, 1);
                    rectTrans.anchorMax = new Vector2(1, 1);
                }
            }
            else
            {
                if (!((rectTrans.anchorMin == new Vector2(0, 1) && rectTrans.anchorMax == new Vector2(0, 1)) ||
                         (rectTrans.anchorMin == new Vector2(0, 0) && rectTrans.anchorMax == new Vector2(0, 1))))
                {
                    rectTrans.anchorMin = new Vector2(0, 0);
                    rectTrans.anchorMax = new Vector2(0, 1);
                }
            }
        }

        //实时刷新列表时用
        public virtual void UpdateList()
        {
            for (int i = 0, length = m_CellInfos.Length; i < length; i++)
            {
                CellInfo cellInfo = m_CellInfos[i];
                if (cellInfo.obj != null)
                {
                    float rangePos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x;
                    if (!IsOutRange(rangePos))
                    {
                        Func(m_FuncCallBackFunc, cellInfo.obj, true);
                    }
                }
            }
        }

        //刷新某一项
        public void UpdateCell(int index)
        {
            CellInfo cellInfo = m_CellInfos[index - 1];
            if (cellInfo.obj != null)
            {
                float rangePos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x;
                if (!IsOutRange(rangePos))
                {
                    Func(m_FuncCallBackFunc, cellInfo.obj);
                }
            }
        }

        public virtual void ShowList(string numStr) { }

        public virtual void ShowList(int num)
        {
            m_MinIndex = -1;
            m_MaxIndex = -1;

            //-> 计算 Content 尺寸
            if (m_Direction == e_Direction.Vertical)
            {
                float contentSize = (m_Y_Spacing + m_CellObjectHeight) * Mathf.CeilToInt((float)num / m_Row);
                m_ContentHeight = contentSize;
                m_ContentWidth = m_ContentRectTrans.sizeDelta.x;
                contentSize = contentSize < rectTrans.rect.height ? rectTrans.rect.height : contentSize;
                m_ContentRectTrans.sizeDelta = new Vector2(m_ContentWidth, contentSize);
                if (num != m_MaxCount)
                {
                    m_ContentRectTrans.anchoredPosition = new Vector2(m_ContentRectTrans.anchoredPosition.x, 0);
                }
            }
            else
            {
                float contentSize = (m_X_Spacing + m_CellObjectWidth) * Mathf.CeilToInt((float)num / m_Row);
                m_ContentWidth = contentSize;
                m_ContentHeight = m_ContentRectTrans.sizeDelta.x;
                contentSize = contentSize < rectTrans.rect.width ? rectTrans.rect.width : contentSize;
                m_ContentRectTrans.sizeDelta = new Vector2(contentSize, m_ContentHeight);
                if (num != m_MaxCount)
                {
                    m_ContentRectTrans.anchoredPosition = new Vector2(0, m_ContentRectTrans.anchoredPosition.y);
                }
            }

            //-> 计算 开始索引
            int lastEndIndex = 0;

            //-> 过多的物体 扔到对象池 ( 首次调 ShowList函数时 则无效 )
            if (m_IsInited)
            {
                lastEndIndex = num - m_MaxCount > 0 ? m_MaxCount : num;
                lastEndIndex = m_IsClearList ? 0 : lastEndIndex;

                int count = m_IsClearList ? m_CellInfos.Length : m_MaxCount;
                for (int i = lastEndIndex; i < count; i++)
                {
                    if (m_CellInfos[i].obj != null)
                    {
                        SetPoolsObj(m_CellInfos[i].obj);
                        m_CellInfos[i].obj = null;
                    }
                }
            }

            //-> 以下四行代码 在for循环所用
            CellInfo[] tempCellInfos = m_CellInfos;
            m_CellInfos = new CellInfo[num];

            //-> 1: 计算 每个Cell坐标并存储 2: 显示范围内的 Cell
            for (int i = 0; i < num; i++)
            {
                // * -> 存储 已有的数据 ( 首次调 ShowList函数时 则无效 )
                if (m_MaxCount != -1 && i < lastEndIndex)
                {
                    CellInfo tempCellInfo = tempCellInfos[i];
                    //-> 计算是否超出范围
                    float rPos = m_Direction == e_Direction.Vertical ? tempCellInfo.pos.y : tempCellInfo.pos.x;
                    if (!IsOutRange(rPos))
                    {
                        //-> 记录显示范围中的 首位index 和 末尾index
                        m_MinIndex = m_MinIndex == -1 ? i : m_MinIndex; //首位index
                        m_MaxIndex = i; // 末尾index

                        if (tempCellInfo.obj == null)
                        {
                            tempCellInfo.obj = GetPoolsObj();
                        }
                        tempCellInfo.obj.transform.GetComponent<RectTransform>().anchoredPosition = tempCellInfo.pos;
                        tempCellInfo.obj.name = i.ToString();
                        tempCellInfo.obj.SetActive(true);

                        Func(m_FuncCallBackFunc, tempCellInfo.obj);
                    }
                    else
                    {
                        SetPoolsObj(tempCellInfo.obj);
                        tempCellInfo.obj = null;
                    }
                    m_CellInfos[i] = tempCellInfo;
                    continue;
                }

                CellInfo cellInfo = new CellInfo();

                float pos = 0;  //坐标( isVertical ? 记录Y : 记录X )
                float rowPos = 0; //计算每排里面的cell 坐标

                // * -> 计算每个Cell坐标
                if (m_Direction == e_Direction.Vertical)
                {
                    pos = m_CellObjectHeight * Mathf.FloorToInt(i / m_Row) + m_Y_Spacing * Mathf.FloorToInt(i / m_Row);
                    rowPos = m_CellObjectWidth * (i % m_Row) + m_X_Spacing * (i % m_Row);
                    cellInfo.pos = new Vector3(rowPos, -pos, 0);
                }
                else
                {
                    pos = m_CellObjectWidth * Mathf.FloorToInt(i / m_Row) + m_X_Spacing * Mathf.FloorToInt(i / m_Row);
                    rowPos = m_CellObjectHeight * (i % m_Row) + m_Y_Spacing * (i % m_Row);
                    cellInfo.pos = new Vector3(pos, -rowPos, 0);
                }

                //-> 计算是否超出范围
                float cellPos = m_Direction == e_Direction.Vertical ? cellInfo.pos.y : cellInfo.pos.x;
                if (IsOutRange(cellPos))
                {
                    cellInfo.obj = null;
                    m_CellInfos[i] = cellInfo;
                    continue;
                }

                //-> 记录显示范围中的 首位index 和 末尾index
                m_MinIndex = m_MinIndex == -1 ? i : m_MinIndex; //首位index
                m_MaxIndex = i; // 末尾index

                //-> 取或创建 Cell
                GameObject cell = GetPoolsObj();
                Vector2 rectSize = cell.GetComponent<RectTransform>().sizeDelta;

                cell.transform.GetComponent<RectTransform>().anchoredPosition = new Vector3(cellInfo.pos.x + (rectSize.x / 2), cellInfo.pos.y - (rectSize.y / 2), cellInfo.pos.z);
                cell.gameObject.name = i.ToString();

                //-> 存数据
                cellInfo.obj = cell;
                m_CellInfos[i] = cellInfo;

                //-> 回调  函数
                Func(m_FuncCallBackFunc, cell);
            }

            m_MaxCount = num;
            m_IsInited = true;

            OnDragListener(Vector2.zero);

        }

        // 更新滚动区域的大小
        public void UpdateSize()
        {
            Rect rect = GetComponent<RectTransform>().rect;
            m_PlaneHeight = rect.height;
            m_PlaneWidth = rect.width;
        }

        //滑动事件
        protected virtual void ScrollRectListener(Vector2 value)
        {
            UpdateCheck();
        }

        private void UpdateCheck()
        {
            if (m_CellInfos == null)
                return;

            //检查超出范围
            for (int i = 0, length = m_CellInfos.Length; i < length; i++)
            {
                CellInfo cellInfo = m_CellInfos[i];
                GameObject obj = cellInfo.obj;
                Vector3 pos = cellInfo.pos;

                float rangePos = m_Direction == e_Direction.Vertical ? pos.y : pos.x;
                SelfUpdateCheck(i, rangePos);
                //判断是否超出显示范围
                if (IsOutRange(rangePos))
                {
                    //把超出范围的cell 扔进 poolsObj里
                    if (obj != null)
                    {
                        SetPoolsObj(obj);
                        m_CellInfos[i].obj = null;
                    }
                }
                else
                {
                    if (obj == null)
                    {
                        //优先从 poolsObj中 取出 (poolsObj为空则返回 实例化的cell)
                        GameObject cell = GetPoolsObj();
                        Vector2 rectSize = cell.GetComponent<RectTransform>().sizeDelta;
                        cell.transform.localPosition = new Vector3(pos.x + (rectSize.x / 2), pos.y - (rectSize.y / 2), pos.z);
                        cell.gameObject.name = i.ToString();
                        m_CellInfos[i].obj = cell;

                        Func(m_FuncCallBackFunc, cell);
                    }
                }
            }
        }

        protected virtual void SelfUpdateCheck(int index, float pos)
        {
        }

        //判断是否超出显示范围
        protected virtual bool IsOutRange(float pos)
        {
            Vector3 listP = m_ContentRectTrans.anchoredPosition;
            if (m_Direction == e_Direction.Vertical)
            {
                if (pos + listP.y > m_CellObjectHeight || pos + listP.y < -rectTrans.rect.height)
                {
                    return true;
                }
            }
            else
            {
                if (pos + listP.x < -m_CellObjectWidth || pos + listP.x > rectTrans.rect.width)
                {
                    return true;
                }
            }
            return false;
        }

        //对象池 机制  (存入, 取出) cell
        protected Stack<GameObject> poolsObj = new Stack<GameObject>();
        //取出 cell
        protected virtual GameObject GetPoolsObj()
        {
            GameObject cell = null;
            if (poolsObj.Count > 0)
            {
                cell = poolsObj.Pop();
            }

            if (cell == null)
            {
                cell = Instantiate(m_CellGameObject) as GameObject;
            }
            cell.transform.SetParent(m_Content.transform);
            cell.transform.localScale = Vector3.one;
            SetActive(cell, true);

            return cell;
        }
        //存入 cell
        protected virtual void SetPoolsObj(GameObject cell)
        {
            if (cell != null)
            {
                poolsObj.Push(cell);
                SetActive(cell, false);
            }
        }

        //回调
        protected void Func(Action<GameObject, int> func, GameObject selectObject, bool isUpdate = false)
        {
            int num = int.Parse(selectObject.name) + 1;
            if (func != null)
            {
                func(selectObject, num);
            }

        }

        public void DisposeAll()
        {
            if (m_FuncCallBackFunc != null)
            {
                m_FuncCallBackFunc = null;
            }
            if (m_FuncOnClickCallBack != null)
            {
                m_FuncOnClickCallBack = null;
            }
        }

        protected void OnDestroy()
        {
            DisposeAll();
        }

        public virtual void OnClickCell(GameObject cell) { }

        //-> ExpandCircularScrollView 函数
        public virtual void OnClickExpand(int index) { }

        //-> FlipCircularScrollView 函数
        public virtual void SetToPageIndex(int index) { }

        public virtual void OnBeginDrag(PointerEventData eventData)
        {

        }

        public void OnDrag(PointerEventData eventData)
        {
        }

        public virtual void OnEndDrag(PointerEventData eventData)
        {

        }

        protected void OnDragListener(Vector2 value)
        {
            float normalizedPos = m_Direction == e_Direction.Vertical ? m_ScrollRect.verticalNormalizedPosition : m_ScrollRect.horizontalNormalizedPosition;

            if (m_Direction == e_Direction.Vertical)
            {
                if (m_ContentHeight - rectTrans.rect.height < 10)
                {
                    SetActive(m_PointingFirstArrow, false);
                    SetActive(m_PointingEndArrow, false);
                    return;
                }
            }
            else
            {
                if (m_ContentWidth - rectTrans.rect.width < 10)
                {
                    SetActive(m_PointingFirstArrow, false);
                    SetActive(m_PointingEndArrow, false);
                    return;
                }
            }

            if (normalizedPos >= 0.9)
            {
                SetActive(m_PointingFirstArrow, false);
                SetActive(m_PointingEndArrow, true);
            }
            else if (normalizedPos <= 0.1)
            {
                SetActive(m_PointingFirstArrow, true);
                SetActive(m_PointingEndArrow, false);
            }
            else
            {
                SetActive(m_PointingFirstArrow, true);
                SetActive(m_PointingEndArrow, true);
            }
        }

        public static void SetActive(GameObject obj, bool isActive)
        {
            if (obj != null)
            {
                obj.SetActive(isActive);
            }
        }
    }
}

代码一挂在ScrollRect上
content锚点左上
在content下方一个要创建的ItemUI锚点左上

代码调用先执行代码一.Init(方法,null);
代码一.ShowList(总长度、大小);
方法(创建出来的物体,创建出来的索引){

}

更方便的教程
https://blog.csdn.net/qq_30259857/article/details/80275920

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值