Пример #1
0
 public void RegisterCellForNib(iCollectionViewCell prefab, string nib)
 {
     if (m_nibs.ContainsKey(nib))
     {
         m_nibs[nib] = prefab;
     }
     else
     {
         m_nibs.Add(nib, prefab);
     }
 }
Пример #2
0
 //This will overwrite any previously registered!
 public void RegisterCell(iCollectionViewCell prefab)
 {
     if (m_nibs.ContainsKey(prefab.NibName))
     {
         m_nibs[prefab.NibName] = prefab;
     }
     else
     {
         m_nibs.Add(prefab.NibName, prefab);
     }
 }
Пример #3
0
    /// <summary>
    /// Register a cell for use with this layout
    /// </summary>
    /// <param name="cell">Cell - iCoverFlowCell being used</param>
    /// <param name="onCellClick">On cell click - Optional OnCellClick event</param>
    public void RegisterCell(iCollectionViewCell cell, EventHandler onCellClick = null)
    {
        //Register pool
        CellPoolService.Instance.RegisterCell(cell);

        NibInUse = cell.NibName;
        if (onCellClick != null)
        {
            OnCellClick = onCellClick;
        }
    }
Пример #4
0
    private void OnCellClickEvent(object sender, EventArgs e)
    {
        if (!m_tapSelectEnabled || m_dragState == DragState.Dragging)
        {
            return;
        }

        iCollectionViewCell cell = sender as iCollectionViewCell;

        if (cell != null && m_layout != null)
        {
            StopDrag();
            m_layout.CurrentIndex = cell.Index;
            Dirty = true;
        }
    }
Пример #5
0
    public iCollectionViewCell CreateCell(string nib, GameObject owner = null)
    {
        //Check we have nib registered
        if (!m_nibs.ContainsKey(nib))
        {
            throw new UnityException(string.Format("No Prefab registered for {0}", nib));
        }

        //Check pool
        if (m_pools.ContainsKey(nib))
        {
            List <iCollectionViewCell> pool = m_pools[nib];

            //Check for any not being used
            foreach (iCollectionViewCell cell in pool)
            {
                if (!cell.IsActive)
                {
                    cell.SetActive(true, owner);
                    return(cell);
                }
            }
        }
        else
        {
            //Make Pool
            m_pools.Add(nib, new List <iCollectionViewCell>());
        }

        //No free cells, so make a new one
        iCollectionViewCell c = m_nibs[nib].CreateCell();

        c.SetActive(true, owner);

        m_pools[nib].Add(c);

        return(c);
    }
Пример #6
0
    /// <summary>
    /// This handles reuse, it will work out the indices we need, add delete/add cell
    /// as needed.
    ///
    /// Call before layout
    /// </summary>
    /// <param name="data">Data - The whole data we are laying out.</param>
    /// <param name="cells">Cells - The array of cells we will add/delete from as needed</param>
    private void PrepareCells(List <object> data, List <iCollectionViewCell> cells)
    {
        int totCells = Math.Min(TotalCellsNeeded, data.Count);

        int curIndex = (int)Math.Round(CurrentIndex);
        int min      = curIndex - (totCells / 2);
        int max      = curIndex + (totCells / 2);

        if (!IndexWrap)
        {
            if (min < 0)
            {
                min = 0;
                max = totCells;
            }
            else if (max >= data.Count)
            {
                max = data.Count;
                min = max - totCells;
            }
        }

        //GO through cells, any with an index we no longer need, turn off
        int minVal = (min < 0) ? min + data.Count : min;
        int maxVal = (max >= data.Count) ? max - data.Count : max;


        if (!IndexWrap)
        {
            if (max >= data.Count)
            {
                maxVal = data.Count - 1;
                minVal = maxVal - m_maxCells;
            }

            min = minVal;
            max = maxVal;
        }


        for (int i = 0; i < cells.Count; i++)
        {
            iCollectionViewCell c = cells[i];
            c.Snap = false;

            //Bizzare annoyance,min and max can sometimes be the same, i.e. we have enough cells for all the data fine
            if (maxVal == minVal)
            {
                continue;
            }

            //If maxval is bigger than minval then just check were in the range
            if (maxVal > minVal && (c.Index <= maxVal && c.Index >= minVal))
            {
                continue;
            }

            //If min value is bigger than max were in a "wrap"
            if (minVal > maxVal && (c.Index >= minVal || c.Index <= maxVal))
            {
                continue;
            }
            c.SetActive(false);
            cells.Remove(c);
            i--;
        }

        //Go through cells, add any indices we need and set their data TODO - How to do this quickly?
        for (int i = min; i <= max; i++)
        {
            int index = i;
            //Wrap index
            if (index < 0)
            {
                index += data.Count;
            }
            else if (index >= data.Count)
            {
                index -= data.Count;
            }

            //Check if we have htis index
            bool found = false;
            foreach (iCollectionViewCell cell in cells)
            {
                if (cell.Index == index)
                {
                    found = true;
                    //Set Data if null
                    if (cell.Data == null)
                    {
                        cell.SetData(data[index]);
                    }
                    break;
                }
            }

            if (!found)
            {
                //Add a new one
                iCollectionViewCell c = CellPoolService.Instance.CreateCell(NibInUse, gameObject);
                c.transform.localPosition = Vector3.zero;
                c.Index = index;
                c.Snap  = true;
                c.SetData(data[index]);

                if (OnCellClick != null)
                {
                    c.OnClickEvent += OnCellClick;
                }

                cells.Add(c);
            }
        }
    }