Example #1
0
        protected virtual ULuaPanelItem GetPoolsObj()
        {
            ULuaPanelItem cell = null;

            if (poolsObj.Count > 0)
            {
                cell = poolsObj.Pop();
            }

            if (cell == null)
            {
                GameObject _itemObj = Instantiate(m_CellGameObject) as GameObject;
                cell = _itemObj.GetComponent <ULuaPanelItem>();
                cell.BuildControl();

                RectTransform rect = cell.transform as RectTransform;
                PanelMgr.AddUIChild(rect, m_Content.transform as RectTransform);

                cell.OnCreate();
                cell.OnOpen();
            }

            cell.gameObject.SetActive(true);

            return(cell);
        }
Example #2
0
 protected virtual void SetPoolsObj(ULuaPanelItem cell)
 {
     if (cell != null)
     {
         poolsObj.Push(cell);
         cell.gameObject.SetActive(false);
     }
 }
Example #3
0
        protected void Func(Action <ILuaPanelItem, int> func, ULuaPanelItem selectObject, bool isUpdate = false)
        {
            int num = int.Parse(selectObject.name) + 1;

            if (func != null)
            {
                func(selectObject.LuaPanelItem, num);
            }
        }
Example #4
0
        private void UpdateCheck()
        {
            if (m_CellInfos == null)
            {
                return;
            }

            for (int i = 0, length = m_CellInfos.Length; i < length; i++)
            {
                CellInfo      cellInfo = m_CellInfos[i];
                ULuaPanelItem obj      = cellInfo.obj;
                Vector3       pos      = cellInfo.pos;

                float rangePos = m_Direction == e_Direction.Vertical ? pos.y : pos.x;
                if (IsOutRange(rangePos))
                {
                    if (obj != null)
                    {
                        SetPoolsObj(obj);
                        m_CellInfos[i].obj = null;
                    }
                }
                else
                {
                    if (obj == null)
                    {
                        ULuaPanelItem cell = GetPoolsObj();
                        cell.transform.localPosition = pos;
                        cell.gameObject.name         = i.ToString();
                        m_CellInfos[i].obj           = cell;

                        Func(OnLoopGridValueChanged, cell);
                    }
                }
            }
        }
Example #5
0
        public virtual void ShowList(int num)
        {
            m_MinIndex = -1;
            m_MaxIndex = -1;

            if (m_Direction == e_Direction.Vertical)
            {
                float contentSize = (m_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_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;

            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;
                    }
                }
            }

            CellInfo[] tempCellInfos = m_CellInfos;
            m_CellInfos = new CellInfo[num];

            for (int i = 0; i < num; i++)
            {
                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))
                    {
                        m_MinIndex = m_MinIndex == -1 ? i : m_MinIndex;
                        m_MaxIndex = i;

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

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

                CellInfo cellInfo = new CellInfo();

                float pos    = 0;
                float rowPos = 0;

                if (m_Direction == e_Direction.Vertical)
                {
                    pos          = m_CellObjectHeight * Mathf.FloorToInt(i / m_Row) + m_Spacing * Mathf.FloorToInt(i / m_Row);
                    rowPos       = m_CellObjectWidth * (i % m_Row) + m_Spacing * (i % m_Row);
                    cellInfo.pos = new Vector3(rowPos, -pos, 0);
                }
                else
                {
                    pos          = m_CellObjectWidth * Mathf.FloorToInt(i / m_Row) + m_Spacing * Mathf.FloorToInt(i / m_Row);
                    rowPos       = m_CellObjectHeight * (i % m_Row) + m_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;
                }

                m_MinIndex = m_MinIndex == -1 ? i : m_MinIndex;
                m_MaxIndex = i;

                ULuaPanelItem cell = GetPoolsObj();
                cell.transform.GetComponent <RectTransform>().anchoredPosition = cellInfo.pos;
                cell.gameObject.name = i.ToString();

                cellInfo.obj   = cell;
                m_CellInfos[i] = cellInfo;

                Func(OnLoopGridValueChanged, cell);
            }

            m_MaxCount = num;
            m_IsInited = true;

            OnDragListener(Vector2.zero);
        }