找回密码
 立即注册
查看: 5693|回复: 76

[ugui/ngui] ngui 在scroll view中动态插入prefab预置对象代码

[复制链接]
发表于 2013-3-22 17:00 | 显示全部楼层 |阅读模式
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();
    }

发表于 2013-3-23 13:25 | 显示全部楼层
gridObj.transform.childCount.ToString() 获取行数{:5_399:}
发表于 2017-2-16 17:22 | 显示全部楼层
好帖就是要顶
发表于 2017-2-16 17:23 | 显示全部楼层
真心顶
发表于 2017-2-16 17:59 | 显示全部楼层
难得一见的好帖
发表于 2017-2-16 17:21 | 显示全部楼层
说的非常好
发表于 2017-2-16 18:07 | 显示全部楼层
很好哦
发表于 2017-3-18 09:31 | 显示全部楼层
好帖就是要顶
发表于 2017-3-18 09:13 | 显示全部楼层
难得一见的好帖
发表于 2017-3-18 09:40 | 显示全部楼层
很好哦
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-4-29 17:48 , Processed in 0.207801 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表