NGUI之scroll view制作,以及踩的坑总结
来源:互联网 发布:ubuntu samba 写权限 编辑:程序博客网 时间:2024/05/19 19:42
链接:
http://game.ceeger.com/forum/read.php?tid=5517
之前也看了不少童鞋谢了关于NGUI的scroll view的制作
下面我写下自己的制作过程以及心得,希望对童鞋们有所帮助。
1.首先建立一个960*640的背景参考http://game.ceeger.com/forum/read.php?tid=5314
效果如图:先借用下三国杀的背景图哈,原图大小是960*640,因为我做的both缩放,很不错的.
2.随便做一个atlas。资源在网上随便找一个,等下作为滑动对象。
3.a)在panel下建立两个空的游戏对象,其中pane(view)是等下要展示的view的部分,panel(window)为辅助view展示的,如图
b)给panel(view)添加uidragable panel(script)并设置参数,如图
备注:clipping选择soft clip
size为你需要展示拖动区域的大小,我的展示区域是横向拉动,满屏,图集高度为280.我这里设置稍微大点。就给了300
最下面是选择scroll bar(稍后会给加上)
4.
a)在panel(view)中新建一个空的游戏对象命名为UIGrid
b)给UIGrid添加uigrid脚本
c)设置uigrid脚本参数
备注:uigrid会对其子对象默认排序...
cell width;cell height指在scroll view中的排列的(或者你认为是uigrid的子对象)元素的高和宽
5.给UIGrid添加子节点(这里我添加一个sprite,官网demo是item下再添加sprite。道理是一样)
a)添加sprite并给sprite加上uidragpanelcontents
并设置如图
b)复制几个sprite
6.给panel(window)加一个拉动区域
如图:
7.panel(window)下添加scroll bar
同时要设置,如图
8.添加两个button,动态添加UIGrid下的节点
效果展示下:
9,给button写脚本
add脚本:
public UIGrid grid;
void Start()
{
//获得UIgrid节点
grid = GameObject.Find("UIGrid").GetComponent<UIGrid>();
//panel = GameObject.Find("Panel-view").GetComponent<UIPanel>();
}
void OnClick()
{
//载入新的atlas
UIAtlas atlas = Resources.Load("cardt", typeof(UIAtlas)) as UIAtlas;
//设置父节点
GameObject parent = GameObject.Find("UIGrid");
//添加
UISprite sprite = NGUITools.AddSprite(parent, atlas, "nvyao");
sprite.MakePixelPerfect();
//重设uigrid
grid.Reposition();
}
del脚本
public UIGrid grid;
void Start() {
//得到grid对象 grid = GameObject.Find("UIGrid").GetComponent<UIGrid>();
}
void OnClick() {
GameObject sprite = GameObject.Find("Sprite"); if (sprite != null)
{ Destroy(sprite);
grid.repositionNow = true; }
}
下面我写下自己的制作过程以及心得,希望对童鞋们有所帮助。
1.首先建立一个960*640的背景参考http://game.ceeger.com/forum/read.php?tid=5314
效果如图:先借用下三国杀的背景图哈,原图大小是960*640,因为我做的both缩放,很不错的.
2.随便做一个atlas。资源在网上随便找一个,等下作为滑动对象。
3.a)在panel下建立两个空的游戏对象,其中pane(view)是等下要展示的view的部分,panel(window)为辅助view展示的,如图
b)给panel(view)添加uidragable panel(script)并设置参数,如图
备注:clipping选择soft clip
size为你需要展示拖动区域的大小,我的展示区域是横向拉动,满屏,图集高度为280.我这里设置稍微大点。就给了300
最下面是选择scroll bar(稍后会给加上)
4.
a)在panel(view)中新建一个空的游戏对象命名为UIGrid
b)给UIGrid添加uigrid脚本
c)设置uigrid脚本参数
备注:uigrid会对其子对象默认排序...
cell width;cell height指在scroll view中的排列的(或者你认为是uigrid的子对象)元素的高和宽
5.给UIGrid添加子节点(这里我添加一个sprite,官网demo是item下再添加sprite。道理是一样)
a)添加sprite并给sprite加上uidragpanelcontents
并设置如图
b)复制几个sprite
6.给panel(window)加一个拉动区域
如图:
7.panel(window)下添加scroll bar
同时要设置,如图
8.添加两个button,动态添加UIGrid下的节点
效果展示下:
9,给button写脚本
add脚本:
public UIGrid grid;
void Start()
{
//获得UIgrid节点
grid = GameObject.Find("UIGrid").GetComponent<UIGrid>();
//panel = GameObject.Find("Panel-view").GetComponent<UIPanel>();
}
void OnClick()
{
//载入新的atlas
UIAtlas atlas = Resources.Load("cardt", typeof(UIAtlas)) as UIAtlas;
//设置父节点
GameObject parent = GameObject.Find("UIGrid");
//添加
UISprite sprite = NGUITools.AddSprite(parent, atlas, "nvyao");
sprite.MakePixelPerfect();
//重设uigrid
grid.Reposition();
}
del脚本
public UIGrid grid;
void Start() {
//得到grid对象 grid = GameObject.Find("UIGrid").GetComponent<UIGrid>();
}
void OnClick() {
GameObject sprite = GameObject.Find("Sprite"); if (sprite != null)
{ Destroy(sprite);
grid.repositionNow = true; }
}
采坑总结:
一、新建一个对象的时候,需要确定这个对象的显示层级(Layer选项)一定要和NGUI摄像机设定的显示层级一样。
二、如果添加的Component中有摄像机选项的话,那么一定要检查摄像机一定要设置成NGUI的摄像机,因为一般场景里面除了NGUI的摄像机之外还有渲染场景物体的摄像机。
三、两个Panel不要设置为同一depth,不然各种调不对。
四、uidragpanelcontents和Colider一定要挂在同一个物体身上,不然不会响应拖拽事件,比如你在Grid对象下挂了一个Item对象,这个Item对象下面有一个Sprite,如果你把uidragpanelcontents放在Sprite上,把Colider放在Item上,那么是不会响应拖拽事件的。
0 0
- NGUI之scroll view制作,以及踩的坑总结
- NGUI之scroll view制作,以及踩的坑总结
- NGUI的Scroll View的制作
- 如何制作NGUI的Scroll View
- NGUI之Scroll View
- Unity NGUI制作scroll view
- 【Unity&NGUI】创建NGUI的Scroll View的一些问题以及拓展
- NGUI 3.0 Scroll View的使用
- NGUI创建Scroll View的基本步骤
- NGUI -- Scroll View
- 【NGUI】循环Scroll View
- Unity3D NGUI Scroll View注意事项
- 【Unity3D】【NGUI】循环Scroll View
- NGUI 例子8 scroll view
- NGUI Scroll View 循环滚动
- unity NGUI tutorial scroll view
- Unity3D NGUI Scroll View注意事项
- NGUI之Scroll Bar
- 自己动手编写CSDN博客备份工具-blogspider
- 快速排序算法
- 科目三考试过程详解
- js Dom 基础知识
- 用C实现了简单的顺序表
- NGUI之scroll view制作,以及踩的坑总结
- Win7 在IIS中增加MIME类型文件
- Mac下安装cocos2d-x
- Pat(Advanced Level)Practice--1021(Deepest Root)
- 线性表之大整数求和
- [LeetCode]Two Sum
- H.264/AVC是什么?
- 继承中的构造函数调用顺序
- linux 启动oracle