示例#1
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;
        }
示例#2
0
    /// <summary>
    /// 初始化渲染脚本
    /// </summary>
    public virtual void InitRendererList(DynamicInfinityItem.OnSelect OnSelect, DynamicInfinityItem.OnUpdateData OnUpdate)
    {
        if (mHasInited)
        {
            return;
        }
        //转换器
        mRectTransformContainer = transform as RectTransform;
        //获得蒙版尺寸
        mMaskSize   = transform.parent.parent.GetComponent <RectTransform>().sizeDelta;
        mScrollRect = transform.parent.parent.GetComponent <ScrollRect>();

        transform.GetComponent <RectTransform>().sizeDelta = Vector2.zero;

        //通过蒙版尺寸和格子尺寸计算需要的渲染器个数
        mRendererCount = ColumnCount * (Mathf.CeilToInt(mMaskSize.y / GetBlockSizeY()) + 1);
        _UpdateDynmicRects(mRendererCount);
        mList_items = new List <DynamicInfinityItem>();
        for (int i = 0; i < mRendererCount; ++i)
        {
            GameObject child = GameObject.Instantiate(RenderGO);
            child.transform.SetParent(transform);
            child.transform.localRotation = Quaternion.identity;
            child.transform.localScale    = Vector3.one;
            child.layer = gameObject.layer;
            DynamicInfinityItem dfItem = child.GetComponent <DynamicInfinityItem>();
            if (dfItem == null)
            {
                throw new Exception("Render must extend DynamicInfinityItem");
            }
            mList_items.Add(dfItem);
            mList_items[i].DRect               = mDict_dRect[i];
            mList_items[i].OnSelectHandler     = OnSelect;
            mList_items[i].OnUpdateDataHandler = OnUpdate;
            child.SetActive(false);
            _UpdateChildTransformPos(child, i);
        }
        _SetListRenderSize(mRendererCount);
        mHasInited = true;
    }