(但是没有复用)
1.初始页面
2.现在给content 添加脚本 ,
在content 我添加了Grid Layout Group 和 Content Size Fitter
简单概述一下:
Grid Layout Group : 类于Android中的布局
Content Size Fitter :属性控制item 占有度
//-----------------------------------------------------------------
3.接下是脚本
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoomList : MonoBehaviour
{
List<GameObject> listItem = new List<GameObject>();//需要添加item对象 后期可更改为数据在根据数据去创建item对象
public Transform parentTransForm;//需要放置content 的参数 ,还没研究透原因就写了
public GameObject item;//item list子类
// Start is called before the first frame update
void Start()
{
for (int i = 0;i<10 ;i++) {
GameObject gameObject = Instantiate(item, parentTransForm);//这方法我还没去看源码,字面意思实例化
listItem.Add(gameObject);//这是我自己在保存对象
}
}
// Update is called once per frame
void Update()
{
}
}
4.运行后展示图,都没有demo
可以一写简单点你要测试的话,我这是刚好写了
补点击事件方法:2019-05-28 16:29
代码
//添加点击事件
gameObject.AddComponent<Button>().onClick.AddListener(delegate() {
this.onCl(gameObject.name);//这方法要自己写哟 这就当前对象名称当做参数
});