GameObject grid下挂入脚本 MultiRowWrapContent
代码:
UIWrapContent _wrapScript = grid_mt_SearchItem_Ingredients.GetComponent<UIWrapContent>();
_wrapScript.onInitializeItem = OnUpdateIngredients;
_wrapScript.onInitializeItem = OnUpdateIngredients;
Range Limit,这个范围是在:-最大数量+1 ~ 0。至于前面的负号,你可以去看看它的实现原理。比如你共显示20条数据,那么范围就是-20+1~0(-19~0)。
_wrapScript.minIndex =-1*Mathf.CeilToInt(data_Ingredients.Count*1.0f/((MultiRowWrapContent) _wrapScript).rownum)+1;
cull content 选项取消勾,才能实现 go.gameObject.SetActive(false);
void OnUpdateIngredients(GameObject go, int index, int realIndex){
datas = data_Ingredients;
if (realIndex < datas.Count)
{
go.gameObject.SetActive(true);
}
else
{
go.gameObject.SetActive(false);
}
}
本文介绍如何使用Unity中的UIWrapContent组件配合MultiRowWrapContent脚本实现场景中网格布局GameObject的动态加载与更新。通过设置_rangeLimit与_minIndex属性控制显示的数据范围,并在OnUpdateIngredients方法中根据实际索引激活或禁用GameObject。
1万+

被折叠的 条评论
为什么被折叠?



