Пример #1
0
        void OnDestroy()
        {
            m_ScrollRect      = null;
            m_Content         = null;
            m_ItemPrefab      = null;
            onRefreshCallBack = null;

            listItem.Clear();
            unUseItem.Clear();



            listItem  = null;
            unUseItem = null;
        }
Пример #2
0
 public void SetCallBack(ScrollViewRefreshCallBack callback)
 {
     this.callBack = callback;
 }
Пример #3
0
        public void UpdateScrollView <T>(IList datas, GameObject prefab, ScrollViewRefreshCallBack callback = null) where T : MonoBehaviour
        {
            onRefreshCallBack = callback;
            if (m_ScrollRect == null || m_Content == null || datas == null)
            {
                Debug.LogError("参数错误");
                return;
            }
            ScrollTo(1, 0);
            _datas     = datas;
            CellWidth  = prefab.GetComponent <RectTransform>().rect.width;
            CellHeight = prefab.GetComponent <RectTransform>().rect.height;
            //             m_ItemPrefab  = GameObject.Instantiate(prefab) as GameObject;
            //             m_ItemPrefab.AddComponent<T>();
            if (prefab.GetComponent <T>() == null)
            {
                prefab.AddComponent <T>();
            }
            m_ItemPrefab = prefab;

            if (alignment == Alignment.eHorizontal)
            {
                ViewCount = Mathf.CeilToInt(transform.parent.GetComponent <RectTransform>().rect.width / CellWidth) + 1;
            }
            else
            {
                ViewCount = Mathf.CeilToInt(transform.parent.GetComponent <RectTransform>().rect.height / CellHeight) + 1;
            }
            if (datas.Count <= 0)
            {
                return;
            }
            setDataCount(datas.Count);

            m_ScrollRect.onValueChanged.RemoveAllListeners();
            m_ScrollRect.onValueChanged.AddListener(onValueChanged);

            unUseItem.Clear();
            listItem.Clear();


            if (alignment == Alignment.eHorizontal && cellAlignMent == CellAlignMent.eCenter)
            {
                setUpdateRectItem(0);
                if (ViewCount > datas.Count / CountOfCol)
                {
                    transform.localPosition = new Vector3(transform.localPosition.x + ((transform.GetComponent <RectTransform>().rect.width - m_Content.GetComponent <RectTransform>().rect.width) / 2), transform.localPosition.y);
                }
                else
                {
                    transform.localPosition = Vector3.zero;
                }
                m_ScrollRect.content.position = new Vector3(m_ScrollRect.content.position.x - m_Content.GetComponent <RectTransform>().rect.width / 2 + transform.GetComponent <RectTransform>().rect.width / 2f, m_ScrollRect.content.position.y);
                setUpdateRectItem(getCurScrollPerLineIndex());
            }
            else if (alignment == Alignment.eVertical && cellAlignMent == CellAlignMent.eCenter)
            {
                setUpdateRectItem(0);
                if (ViewCount > datas.Count / CountOfCol)
                {
                    transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y - ((transform.GetComponent <RectTransform>().rect.height - m_Content.GetComponent <RectTransform>().rect.height) / 2));
                }
                else
                {
                    transform.localPosition = Vector3.zero;
                }
                m_ScrollRect.content.position = new Vector3(m_ScrollRect.content.position.x, m_ScrollRect.content.position.y + m_Content.GetComponent <RectTransform>().rect.height / 2 - transform.GetComponent <RectTransform>().rect.height / 2f);
                setUpdateRectItem(getCurScrollPerLineIndex());
            }
            else
            {
                setUpdateRectItem(0);
            }
        }