Exemple #1
0
        private void CheckItems()
        {
            if (m_itemWidth <= 0 || m_itemHeight <= 0 || template == null)
            {
                return;
            }

            int nbRow = /*Mathf.CeilToInt*/ (int)(height / m_itemHeight);
            int nbCol = /*Mathf.CeilToInt*/ (int)(width / m_itemWidth);

            UIScrollbar scrollbar = parent.parent.GetComponentInChildren <UIScrollbar>();

            if (scrollbar != null)
            {
                scrollbar.isVisible = nbRow > 1;
            }

            int nbItems = nbCol * nbRow;

            if (m_items == null)
            {
                m_items = new FastList <I>();
                m_items.SetCapacity(nbItems);
            }

            if (m_items.m_size < nbItems)
            {
                // Adding missing items
                for (int i = m_items.m_size; i < nbItems; i++)
                {
                    m_items.Add(new I());

                    /*m_items.Add(new I()
                     *  {
                     *      item = CreateItem()
                     *  });
                     *
                     * m_items.m_buffer[i].Init();*/
                }
            }
            else if (m_items.m_size > nbItems)
            {
                // Remove excess items
                for (int i = nbItems; i < m_items.m_size; i++)
                {
                    if (m_items.m_buffer[i].component != null)
                    {
                        Destroy(m_items.m_buffer[i].component.gameObject);
                    }
                }

                m_items.SetCapacity(nbItems);
            }
        }
Exemple #2
0
        private void CheckRows()
        {
            // Debug.Log("CargoSpy - UIFastList.CheckRows()");
            if (m_panel == null || m_rowHeight <= 0)
            {
                return;
            }

            int nbRows = Mathf.CeilToInt(height / m_rowHeight) + 1;

            if (m_rows == null)
            {
                m_rows = new FastList <IUIFastListRow>();
                m_rows.SetCapacity(nbRows);
            }

            if (m_rows.m_size < nbRows)
            {
                // Adding missing rows
                for (int i = m_rows.m_size; i < nbRows; i++)
                {
                    m_rows.Add(m_panel.AddUIComponent(m_rowType) as IUIFastListRow);
                    if (m_canSelect && !selectOnMouseEnter)
                    {
                        m_rows[i].eventClick += OnRowClicked;
                    }
                    else if (m_canSelect)
                    {
                        m_rows[i].eventMouseEnter += OnRowClicked;
                    }
                }
            }
            else if (m_rows.m_size > nbRows)
            {
                // Remove excess rows
                for (int i = nbRows; i < m_rows.m_size; i++)
                {
                    Destroy(m_rows[i] as UnityEngine.Object);
                }

                m_rows.SetCapacity(nbRows);
            }

            UpdateScrollbar();
        }