ngui 在scroll view中动态插入prefab预置对象代码
public UIGrid grid;int count = 1;
void OnClick()
{
/* UIAtlas atlas = Resources.Load("Fantasy Atlas", typeof(UIAtlas)) as UIAtlas;
GameObject parent = GameObject.Find("Grid");
UISprite sprite = NGUITools.AddSprite(parent,atlas,"Window");
sprite.MakePixelPerfect();
grid.Reposition();*/
GameObject obj = (GameObject)Instantiate(Resources.Load("Item"));
obj.name = "Item" + count;
obj.transform.parent = GameObject.Find("Grid").transform;
//这里需重置一下坐标,因为创建时是在外部创建的
GameObject item = GameObject.Find(obj.name);
item.transform.localPosition = new Vector3(0,0,0);
item.transform.localScale= new Vector3(1,1,1);
count++;
grid.Reposition();
}
gridObj.transform.childCount.ToString() 获取行数{:5_399:} 好帖就是要顶 真心顶 难得一见的好帖 说的非常好 很好哦 好帖就是要顶 难得一见的好帖 很好哦
页:
[1]