Example #1
0
        public UISListItem addItem(object data, int id = 0)
        {
            UISListItem it = null;

            if (mCach.Count > 0)
            {
                it = mCach[0];
                mCach.RemoveAt(0);
                mItems.Add(it);
            }

            if (it == null)
            {
                GameObject go = GameObject.Instantiate(mPrefab.gameObject) as GameObject;
                go.transform.SetParent(transform, false);
                it = go.GetComponent <UISListItem>();
                it.onSelectChange = onSelected;
                mItems.Add(it);
            }
            it.setData(data, id);
            it.gameObject.SetActive(true);
            if (mReverse)
            {
                it.transform.SetAsFirstSibling();
            }
            else
            {
                it.transform.SetAsLastSibling();
            }
            return(it);
        }
Example #2
0
 public void delItem(UISListItem it)
 {
     if (!mItems.Remove(it))
     {
         return;
     }
     it.gameObject.SetActive(false);
     mCach.Add(it);
 }
Example #3
0
 public void clearItem()
 {
     for (int i = 0, max = mItems.Count; i < max; ++i)
     {
         UISListItem it = mItems[i];
         it.selected = false;
         it.gameObject.SetActive(false);
     }
     mCach.AddRange(mItems);
     mItems.Clear();
 }
Example #4
0
 public UISListItem getFirstSelected()
 {
     for (int i = 0, max = mItems.Count; i < max; ++i)
     {
         UISListItem it = mItems[i];
         if (it.selected)
         {
             return(it);
         }
     }
     return(null);
 }
Example #5
0
        public List <UISListItem> getSelected()
        {
            List <UISListItem> sels = new List <UISListItem>();

            for (int i = 0, max = mItems.Count; i < max; ++i)
            {
                UISListItem it = mItems[i];
                if (it.selected)
                {
                    sels.Add(it);
                }
            }
            return(sels);
        }
Example #6
0
 void onSelected(UISListItem sel)
 {
     if (mMultiSelect)
     {
         sel.selected = !sel.selected;
     }
     else
     {
         for (int i = 0, max = mItems.Count; i < max; ++i)
         {
             UISListItem it = mItems[i];
             it.selected = object.ReferenceEquals(it, sel);
         }
     }
     if (null != onSelectedChange)
     {
         onSelectedChange(sel);
     }
 }
Example #7
0
 void Awake()
 {
     mPrefab = GetComponentInChildren <UISListItem>();
     mPrefab.gameObject.SetActive(false);
 }