private void InitItem() { //读取配置 Activity activity = FishConfig.Instance.activity; UIGrid uIGrid = List.GetComponent<UIGrid>(); foreach (ActivityInfo info in activity.list) { //AddChild表示实例化并放到这个物体下 Transform go = NGUITools.AddChild(List, Item).transform; go.GetChild(0).GetComponent<UILabel>().text = info.Time; go.GetChild(1).GetComponent<UILabel>().text = info.Title; go.GetChild(2).GetComponent<UILabel>().text = info.Des; go.gameObject.SetActive(true); } //重新排列 uIGrid.repositionNow = true; uIGrid.maxPerLine = 5; //重设uigrid uIGrid.Reposition(); }
NGUI的物体不能用Instantiate方法实例化,然后用SetParent是会爆炸的,位置缩放不对
所以用NGUITools.AddChild(parent,Prefab)实例化并在父物体下面,返回一个实例化后的GameObject