Esempio n. 1
0
 /// <summary>
 /// 添加一项
 /// </summary>
 /// <param name="item"></param>
 /// <returns>返回该项的索引</returns>
 public virtual int AddItem(UIControl_ListItemBase item)
 {
     //_comGrid.AddChild(item.transform);
     item.transform.SetParent(_comGrid.transform);
     item.transform.localScale = Vector3.one;
     _lstItems.Add(item);
     ReSort();
     return(_lstItems.Count - 1);
 }
Esempio n. 2
0
 /// <summary>
 /// 按对象移除
 /// </summary>
 /// <param name="item"></param>
 public virtual void Remove(UIControl_ListItemBase item)
 {
     for (int i = 0; i < _lstItems.Count; ++i)
     {
         if (_lstItems[i] == item)
         {
             RemoveItemAt(i);
             break;
         }
     }
 }
 void RemoveToPool(UIControl_ListItemBase item)
 {
     item.transform.SetParent(null);
     //_comGrid.RemoveChild(item.transform);
     item.transform.SetParent(_goPoolParent.transform);
     item.gameObject.SetActive(false);
     // 如果超出了池子的限制,则删除
     if (_nPoolMax > 0 &&
         _stackPool.Count == _nPoolMax)
     {
         Destroy(item.gameObject);
     }
     else
     {
         _stackPool.Push(item);
     }
 }
 /// <summary>
 /// 虽然有个prefab参数,貌似可以填充任意的ItemBase,
 /// 但实际每次只能传入同一个prefab,否则池子可不会区分你两个prefab的不同
 /// 如果传入的prefab不同,出现什么后果我可不管
 /// </summary>
 /// <param name="prefab"></param>
 /// <param name="dosth"></param>
 /// <returns></returns>
 public override UIControl_ListItemBase CreateAndAddItem(UIControl_ListItemBase prefab, System.Action <UIControl_ListItemBase> dosth = null)
 {
     // 如果池子里面有
     if (_stackPool.Count > 0)
     {
         UIControl_ListItemBase item = _stackPool.Pop();
         item.gameObject.SetActive(true);
         AddItem(item);
         if (dosth != null)
         {
             dosth(item);
         }
         return(item);
     }
     // 否则就创建个新的
     return(base.CreateAndAddItem(prefab, dosth));
 }
Esempio n. 5
0
        /// <summary>
        /// 根据prefab创建一个新的item,并添加到列表中
        /// </summary>
        /// <param name="prefab">要实例化的预制体</param>
        /// <returns>实例化的item</returns>
        public virtual UIControl_ListItemBase CreateAndAddItem(UIControl_ListItemBase prefab, System.Action <UIControl_ListItemBase> dosth = null)
        {
            GameObject clone = Instantiate(prefab.gameObject, _comGrid.transform.position, Quaternion.identity) as GameObject;// NGUITools.AddChild(gameObject, prefab.gameObject);

            clone.transform.SetParent(gameObject.transform);
            //clone.transform.localPosition = Vector3.zero;
            clone.gameObject.SetActive(true);
            clone.transform.localScale = Vector3.one;

            UIControl_ListItemBase item = clone.GetComponent <UIControl_ListItemBase>();

            AddItem(item);
            if (dosth != null)
            {
                dosth(item);
            }
            return(item);
        }