Here are the examples of the csharp api System.Collections.Generic.List.Add(iCollectionViewCell) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
View Source File : CollectionViewLayout.cs
License : MIT License
Project Creator : IainS1986
License : MIT License
Project Creator : IainS1986
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);
}
}
}
19
View Source File : CellPoolService.cs
License : MIT License
Project Creator : IainS1986
License : MIT License
Project Creator : IainS1986
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;
}