Example #1
0
        protected override void LayOut(LoopItem loopItem) //
        {
            RectTransform rectTran = loopItem.transform;
            int           index    = loopItem.index;
            // LayoutRebuilder.ForceRebuildLayoutImmediate(rectTran);
            var rect = rectTran.rect;

            rect.height = -Mathf.Abs(rect.height);
            Vector2 pos = Vector2.zero;

            if (this.columns == 0)                                                  //单行
            {
                pos.x = (rect.width + this.halfPadding) * index + this.halfPadding; // + rect.width * .5f;
                if (rectTran.anchorMax.y - rectTran.anchorMin.y >= 0.99f)           //表示高度适配
                {
                    var offsetMin = rectTran.offsetMin;
                    var offsetMax = rectTran.offsetMax;
                    offsetMin.y        = halfPadding;
                    offsetMax.y        = -halfPadding;
                    rectTran.offsetMin = offsetMin;
                    rectTran.offsetMax = offsetMax;
                }
                else
                {
                    pos.y = -halfPadding;
                }
            }
            else if (columns == 1)                                        //单列 需要宽度适配
            {
                if (rectTran.anchorMax.x - rectTran.anchorMin.x >= 0.99f) //表示宽度适配
                {
                    var offsetMin = rectTran.offsetMin;
                    var offsetMax = rectTran.offsetMax;
                    offsetMin.x        = halfPadding;
                    offsetMax.x        = -halfPadding;
                    rectTran.offsetMin = offsetMin;
                    rectTran.offsetMax = offsetMax;
                }
                else
                {
                    pos.x = halfPadding;
                }
                pos.y = (rect.height - this.halfPadding) * index - this.halfPadding; // rect.height * .5f ;
            }
            else // 多行
            {
                int x = index % columns;
                pos.x = (rect.width + this.halfPadding) * x + this.halfPadding;  // + rect.width * .5f;
                int y = index / columns;
                pos.y = (rect.height - this.halfPadding) * y - this.halfPadding; // rect.height * .5f ;
            }
            rect.position = pos;
            pos           = pos + m_ContentLocalStart; //开始位置

            loopItem.rect = rect;
            rectTran.anchoredPosition3D = Vector3.zero;
            rectTran.anchoredPosition   = pos;
        }
Example #2
0
 void OnDestroy()
 {
     if (clickBtn)
     {
         clickBtn.onClick.RemoveListener(OnSelect);
     }
     clickBtn       = null;
     loopItem       = null;
     loopScrollBase = null;
 }
Example #3
0
        public void OnSelect(LoopItem loopItem)  //选中
        {
            int lastIdx = m_SelectedIndex;

            m_SelectedIndex = loopItem.index;
            if (onSelected != null)
            {
                onSelected(this.parameter, loopItem.item, loopItem.index, lastIdx);
            }
            if (itemCommand != null && itemCommand.CanExecute(new int[] { loopItem.index, lastIdx }))
            {
                itemCommand.Execute(new int[] { loopItem.index, lastIdx });
            }
        }
Example #4
0
        protected bool InitItemStyle(LoopItem loopItem)
        {
            var loopItemSelect = loopItem.item.GetComponent <ILoopSelectStyle>();

            if (loopItemSelect != null)
            {
                loopItemSelect.InitSytle(loopItem, this);
                if (m_SelectedIndex == loopItem.index)
                {
                    m_SelecteStyle = loopItemSelect;
                    // m_SelecteStyle.SelectedStyle();
                    return(true);
                }
            }
            return(false);
        }
Example #5
0
        public void OnSelect(LoopItem loopItem)  //选中
        {
            m_LastSelectedIndex = m_SelectedIndex;
            m_SelectedIndex     = loopItem.index;
            if (onSelected != null)
            {
                onSelected(this.parameter, loopItem.item, m_SelectedIndex, m_LastSelectedIndex);
            }
            object para = null;

            if (itemParameter == null)
            {
                para = loopItem.item;
            }
            else
            {
                para = itemParameter;
            }
            if (itemCommand != null && itemCommand.CanExecute(para))
            {
                itemCommand.Execute(para);
            }
        }
Example #6
0
 ///<summary>
 /// 布局
 ///</summary>
 protected abstract void LayOut(LoopItem loopItem);
Example #7
0
        protected void RenderItem(LoopItem loopItem, int idx)
        {
            var oldRect = loopItem.rect;
            var oldIdx  = loopItem.index;

            loopItem.index = idx;
            // Debug.LogFormat ("RenderItem({1},{0})", loopItem.item, idx);
            if (loopItem.item == null && onGetItem == null)
            {
                var trans = itemSource.GetComponent <RectTransform> ();
                var item  = GameObject.Instantiate(itemSource, trans.position, trans.rotation, content);
                loopItem.item      = item;
                loopItem.transform = item.GetComponent <RectTransform> ();
                if (onInstantiated != null)
                {
                    onInstantiated(this.parameter, loopItem.item, loopItem.index);
                }

                var LoopItemSelect = item.GetComponent <LoopItemSelect> ();
                if (LoopItemSelect != null)
                {
                    LoopItemSelect.InitLoopItem(loopItem, this);
                }
            }

            if (onGetItem != null)
            {
                var item = onGetItem(this.parameter, idx, loopItem.item, oldIdx, content);  //
                var rent = item.GetComponent <RectTransform> ();
                if (rent.parent == null)
                {
                    rent.SetParent(content);
                    rent.rotation   = Quaternion.Euler(0, 0, 0);
                    rent.localScale = Vector3.one;
                    Vector3 newPos = Vector3.zero;
                    newPos.x = halfPadding;
                    rent.anchoredPosition = newPos;
                }
                loopItem.transform = rent;
                loopItem.item      = item;

                var LoopItemSelect = item.GetComponent <LoopItemSelect> ();
                if (LoopItemSelect != null)
                {
                    LoopItemSelect.InitLoopItem(loopItem, this);
                }
            }

            var gObj = loopItem.item.gameObject;

            if (idx >= dataLength)
            {
                gObj.SetActive(false);
                return;
            }
            else if (!gObj.activeSelf)
            {
                gObj.SetActive(true);
            }

            onItemRender(this.parameter, loopItem.item, loopItem.index);  //填充内容
            LayOut(loopItem);
        }
Example #8
0
 void OnDestroy()
 {
     loopItem       = null;
     loopScrollBase = null;
 }
Example #9
0
 public void InitLoopItem(LoopItem loopItem, ILoopSelect loopScrollBase)
 {
     this.loopItem       = loopItem;
     this.loopScrollBase = loopScrollBase;
 }