最新版本的NGUI的ngui uigridd怎么没有Reposition

NGUI 使用UITable(或UIGrid)注意事项
在ScrollView显示区域中,若Item数量不足以超出显示区域,有可能不是贴着ScrollView最边缘位置显示!这个时候可以按如下方法调整:
因为实际情况中,往ScrollView中添加Item往往是动态添加的,而UITable的Transform(默认的position属性是x=0,y=0,z=0)要根据实际情况进行调整!
比如,在垂直拖动ScrollView的情况下,可以先右击UITable然后添加一个Item,接着运行工程(此时如果UITable的Transform中的position属性是默认的x=0, y=0, z=0的话,则Item不会显示在ScrollView的上方位置),这个时候拖动UITable到需要显示的位置,记下此时UITable的Transform属性,然后回到编辑状态,根据这个值调整UITable的Transform属性!再次运行工程就可以看到Item显示在正确的位置了。
动态添加Item就直接load完预设体之后就使用NGUITools.AddChild(UITable.GameObject, ItemGameObject),最后使用UITable.repositionNow = true,这样就可以了
另外,添加拖拽效果时,注意要为加多一个带有以下红色框框中组件的GameObject,然后放在拖拽区域,不然是无法在整个拖拽区域拖动在UITable之下的Item的!
以上只是自己的备注
> 本站内容系网友提交或本网编辑转载,其目的在于传递更多信息,并不代表本网赞同其观点和对其真实性负责。如涉及作品内容、版权和其它问题,请及时与本网联系,我们将在第一时间删除内容!
UITable:这个控件可以方便的排列其他小组件,并能控制小组件之间的距离. 效果如下: 这个控件的效果和UIGrid很相似,区别是UIGrid能控制每个小组件的大小,而这个 控件控制的是小组件之前的空隙.
在使用pooling的时候经常会遇到UITable需要排序的情况 在开启了UITable的Sort之后回发现,默认是对子项的name属性进行升序的 但问题出现于我们经常用数字(例如循环中的i)命名这些子项,如1.2.3...8.9.10.11 一经排序就成了1.10.11.2.3... 原因是UITable脚本排序是按照(string)Name而不是(int ...
可以动态删除创建排序.
unity开发 --------- NGUI UITable与UIGrid相似,都是实现自动排序的.但UIGrid的元素大小是由我们来指定的,而Table中的元素的大小是根据元素本身计算出来的. UITable还保存了元素的顺序List&Transform&.每次重排序,都会更新此List.除了要计算元素的Bound和保存List外,其他基本与U ...
转载于:http. 你是不是对 UIGrid 和 UITable 定位计算方法还模糊不清,那么这篇文章就是你需要的. NGUI 提供了 Grid 和 Table 组件,支持的参数很少,功能也很鸡肋,完全不能像 CSS 的 Box 模型那样随心所欲的布局,而且使用 UIGrid 和 UITable 的时候经常会相对 UIGrid
对于UIScrollView存在大量item的时候,性能不佳一直被人诟病.然后很多人也弄了不错的方案,但感觉都不够美观,我觉得这个东西其实没有那么复杂.找了下原因,也很简单,因为NGUI在更新组件的时候,并不会判断是否可见,也就是说只要你scroll滑动了,那么所有的item都会重新draw一次.那当然会卡了.
既然原因这么明显, ...
在NGUI中,ScrollView是一个非常棒的界面,不过刚开始使用的时候一直一些事项没有搞懂,现在算是明白了,可以轻松上手了,下面把一些注意的问题写出来分享一下. 一个是回弹问题,开始做的时候,一直没有明白例子中那个回弹的效果是如何实现,如图这样的效果 确实这个效果在IOS上非常流行,用户体验也很棒,它的原理也是利用一个UIDragPanelContent ...
unity开发 --------- NGUI
UIGrid可以实现多个gameobject自动排序.可以设定其排序方向.每个元素的宽度,高度等. public Arrangement arrangement = Arrangement.H public int maxPerLine = 0; public float cellWid ...最新版本的NGUI的UIGrid怎么没有Reposition_百度知道12231人阅读
Unity3D(23)
/forum/read.php?tid=5517
之前也看了不少童鞋谢了关于NGUI的scroll view的制作
下面我写下自己的制作过程以及心得,希望对童鞋们有所帮助。
1.首先建立一个960*640的背景参考
效果如图:先借用下三国杀的背景图哈,原图大小是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(稍后会给加上)
a)在panel(view)中新建一个空的游戏对象命名为UIGrid
b)给UIGrid添加uigrid脚本
c)设置uigrid脚本参数
备注:uigrid会对其子对象默认排序...
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写脚本
&public UIG
&& &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 UIA
&& & & &//设置父节点
&& & & &GameObject parent = GameObject.Find(&UIGrid&);
&& & & &//添加
&& & & &UISprite sprite = NGUITools.AddSprite(parent, atlas, &nvyao&);
&& & & &sprite.MakePixelPerfect();
&& & & &//重设uigrid
&& & & &grid.Reposition();
&public UIG
&& &void Start() & &{
&& & & &//得到grid对象 & & & &grid = GameObject.Find(&UIGrid&).GetComponent&UIGrid&();
&& &void OnClick() & &{
&& & & &GameObject sprite = GameObject.Find(&Sprite&); & & & &if (sprite != null)
&& & & &{ & & & & & &Destroy(sprite);
&& & & & & &grid.repositionNow = & & & &}
采坑总结:
& & & & & & & & & 一、新建一个对象的时候,需要确定这个对象的显示层级(Layer选项)一定要和NGUI摄像机设定的显示层级一样。
& & & & & & & & & 二、如果添加的Component中有摄像机选项的话,那么一定要检查摄像机一定要设置成NGUI的摄像机,因为一般场景里面除了NGUI的摄像机之外还有渲染场景物体的摄像机。
& & & & & & & & & 三、两个Panel不要设置为同一depth,不然各种调不对。
& & & & & & & & & 四、uidragpanelcontents和Colider一定要挂在同一个物体身上,不然不会响应拖拽事件,比如你在Grid对象下挂了一个Item对象,这个Item对象下面有一个Sprite,如果你把uidragpanelcontents放在Sprite上,把Colider放在Item上,那么是不会响应拖拽事件的。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:207436次
积分:1979
积分:1979
排名:第14211名
原创:22篇
转载:34篇
评论:20条
(2)(11)(19)(8)(6)(2)(8)114网址导航UIGrid Reposition()
Pages: [1]
Topic: UIGrid Reposition() &(Read 4376 times)
on: May 23, :42 AM »
I'm having a recurring problem that I've solved in the past but can't remember how to fix.When I initially instantiate children in my grid gameobject (within a scroll panel), they appear in the correct position -- in this case going down vertically from the top of the box.Returning to the same panel causes the children to be destroyed and regenerated, and I call Reposition() in UIGrid. But the new objects appear in the center of the grid, leaving a bunch of empty space at the top.The weird thing -- clicking respositionNow in the editor causes the new objects to align properly.I saw in a past post, ArenMook suggested using NGUITools.Destroy instead of Destroy, so I did that. No difference. I even tried throwing Reposition() into a coroutine with a lengthy yield before it. The only thing that helps is clicking repositionNow in the editor. Final detail -- all of this is nearly identical to a past script that has been successful for me. Weird.Thoughts? My code is currently laid out in this order& & & & & & & & for (int i = 0; i & gridObjs.Length; i++) {& & & & & & & & & & & & NGUITools.Destroy(gridObjs[i].gameObject);& & & & & & & & }&(skipping ahead...)&& & & & & & & & foreach (var n in rankPlayers.OrderByDescending(x =& x.Value)) {& & & & & & & & & & & & rank = NGUITools.AddChild(friendsScreen, rankPrefab);& & & & & & & & & & & & rank.transform.localScale +=
Vector3 (1.2f, 1.2f, 0f);& & & & & & & & & & & & rank.transform.parent = grid.transform;& & & & & & & & & & & & rankCont = n.Key.GetComponent&PlayerCont&();& & & & & & & & & & & & newRank = rank.transform.Find (&Label&).gameObject.GetComponent&UILabel&();& & & & & & & & & & & & newRank.text = (&#& + rankInt + & && + rankCont.myName + & &-- && + (int)(rankCont.gallery));& & & & & & & & & & & & rankInt++;& & & & & & & & } & & & & & & & & & & & & & & & & & & & & & & & rankPlayers.Clear();& & & & & & & & & & & & & & & & grid.GetComponent&UIGrid&().Reposition();&:
« Reply #1 on: May 23, :01 AM »
As usual, the moment I posted the question I thought of another thing to try.The answer seems to be calling Reposition() both before and after instantiating a new group of objects. Perhaps the padding that was between the old objects is left over when they're destroyed.
« Reply #2 on: October 17, :04 PM »
I use Reposition() before and after instantiate item,but it dosen't work.And if I use NGUITools.Destroy(),there has some redundant items.I use NGUI3.0.2.
« Reply #3 on: October 17, :01 PM »
I refresh when WaitForEndOfFrame(),it's the only way I found.
« Reply #4 on: June 16, :23 PM »
has anyone solved this problem?I'm seeing the same... and can't solve.
« Reply #5 on: September 09, :07 PM »
Interestingly enough, I had much better results with this: (note: GetChildList)foreach (Transform child in buttonGrid.GetChildList()){& &NGUITools.Destroy(child.gameObject);}&before, I was using this and getting wrong child counts and was unable to have the grid successfully reposition:foreach (Transform child in buttonGrid.transform()){& &NGUITools.Destroy(child.gameObject);}&
« Reply #6 on: September 10, :40 AM »
NGUITools.Destroy unparents the object, so you are iterating through a list that you're modifying... that's a recipe for disaster.
Pages: [1]

我要回帖

更多关于 ngui uigrid 立即刷新 的文章

 

随机推荐