private UIAtlas viewAt;
public int num; // 贴图数量
public UIGrid basicGrid;
// Use this for initialization
void Start()
{
viewAt = Resources.Load("png/ScrollView", typeof(UIAtlas)) as UIAtlas;
for (int i = 0; i < num; i++)
{
GameObject go = (GameObject)Instantiate(Resources.Load("basic"));
go.name = "basic" + i;
go.GetComponent<UISprite>().atlas = viewAt;
go.GetComponent<UISprite>().spriteName = i.ToString();
go.transform.parent = basicGrid.transform;
go.transform.localPosition = new Vector3(0, 0, 0);
go.transform.localScale = new Vector3(1, 1, 1);
basicGrid.repositionNow = true;
UIEventListener.Get(go).onClick = ClickBt;
}
}
/// <summary>
/// 点击图片 逻辑判断
/// </summary>
/// <param name="_go"></param>
void ClickBt(GameObject _go)
{
Debug.Log(_go.name);
}
NGUI 动态加载item
最新推荐文章于 2019-02-07 20:36:58 发布