Beispiel #1
0
 /// <summary>
 /// 清理可复用渲染格
 /// 不需要public
 /// </summary>
 void _ClearAllListRenderDr()
 {
     if (_listItems != null)
     {
         int len = _listItems.Count;
         for (int i = 0; i < len; ++i)
         {
             DynamicInfinityItem item = _listItems[i];
             item.DRect = null;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获得待渲染的渲染器
        /// </summary>
        /// <returns></returns>
        DynamicInfinityItem _GetNullDynmicItem()
        {
            int len = _listItems.Count;

            for (int i = 0; i < len; ++i)
            {
                DynamicInfinityItem item = _listItems[i];
                if (item.DRect == null)
                {
                    return(item);
                }
            }
            throw new Exception("Error");
        }
Beispiel #3
0
        /// <summary>
        /// 通过动态格子获得动态渲染器
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        DynamicInfinityItem _GetDynmicItem(DynamicRect rect)
        {
            int len = _listItems.Count;

            for (int i = 0; i < len; ++i)
            {
                DynamicInfinityItem item = _listItems[i];
                if (item.DRect == null)
                {
                    continue;
                }
                if (rect.Index == item.DRect.Index)
                {
                    return(item);
                }
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// 初始化渲染脚本
        /// </summary>
        virtual public void InitRendererList(DynamicInfinityItem.OnSelect OnSelect, DynamicInfinityItem.OnUpdateData OnUpdate)
        {
            if (_hasInited)
            {
                return;
            }
            //转换器
            _rectTransformContainer = transform as RectTransform;
            //获得蒙版尺寸
            _maskSize   = transform.parent.GetComponent <RectTransform>().rect.size;
            _scrollRect = transform.parent.GetComponent <ScrollRect>();
            //通过蒙版尺寸和格子尺寸计算需要的渲染器个数
            _rendererCount = columnCount * (Mathf.CeilToInt(_maskSize.y / _GetBlockSizeY()) + 1);
            _UpdateDynmicRects(_rendererCount);
            _listItems = new List <DynamicInfinityItem>();
            RectTransform rectTran = null;

            for (int i = 0; i < _rendererCount; ++i)
            {
                GameObject child = GameObject.Instantiate(renderGO);
                rectTran = child.GetComponent <RectTransform>();
                rectTran.SetParent(transform);
                rectTran.localRotation = Quaternion.identity;
                rectTran.localScale    = Vector3.one;
                child.layer            = gameObject.layer;
                DynamicInfinityItem dfItem = child.GetComponent <DynamicInfinityItem>();
                if (dfItem == null)
                {
                    throw new Exception("Render must extend DynamicInfinityItem");
                }
                _listItems.Add(dfItem);
                _listItems[i].DRect               = _dictDRect[i];
                _listItems[i].OnSelectHandler     = OnSelect;
                _listItems[i].OnUpdateDataHandler = OnUpdate;
                child.SetActive(false);
                _UpdateChildTransformPos(child, i);
            }
            _SetListRenderSize(_rendererCount);
            _hasInited = true;
        }
Beispiel #5
0
        protected void _UpdateRender()
        {
            _rectMask.y = -_maskSize.y - _rectTransformContainer.anchoredPosition.y;
            _inOverlaps.Clear();
            foreach (DynamicRect dR in _dictDRect.Values)
            {
                if (dR.Overlaps(_rectMask))
                {
                    _inOverlaps.Add(dR.Index, dR);
                }
            }
            int len = _listItems.Count;

            for (int i = 0; i < len; ++i)
            {
                DynamicInfinityItem item = _listItems[i];
                if (item.DRect != null && !_inOverlaps.ContainsKey(item.DRect.Index))
                {
                    item.DRect = null;
                }
            }
            foreach (DynamicRect dR in _inOverlaps.Values)
            {
                if (_GetDynmicItem(dR) == null)
                {
                    DynamicInfinityItem item = _GetNullDynmicItem();
                    item.DRect = dR;
                    _UpdateChildTransformPos(item.gameObject, dR.Index);

                    if (_dataProviders != null && dR.Index < _dataProviders.Count)
                    {
                        item.SetData(_dataProviders[dR.Index]);
                    }
                }
            }
        }