NGUI UIGrid 动态刷新布局 && BUG FIX

 1     /// <summary>
 2     /// "1" => 对应的一个UISpirte,"1234" => 对应四个预设
 3     /// </summary>
 4     /// <param name="scoreGrid"> 设置中间为锚点 </param>
 5     /// <param name="curScore">like "1234"</param>
 6     /// <param name="numberPrefab"> 对应 的 预设</param>
 7     /// <returns></returns>
 8     IEnumerator ShowScore(UIGrid scoreGrid, string curScore, GameObject numberPrefab)
 9     {
10         foreach (Transform item in scoreGrid.transform)
11         {
12             Destroy(item.gameObject);
13         }
14 
15         //一定要 加上 这一局  不然 设置 grid 中间为锚点 Reposition() 不是预期的那样
16         yield return new WaitForEndOfFrame();
17 
18 
19         char[] number = curScore.ToCharArray();
20         for (int i = 0; number != null && i < number.Length; i++)
21         {
22             GameObject child = NGUITools.AddChild(scoreGrid.gameObject, numberPrefab);
23             UISprite showNum = child.GetComponent<UISprite>();
24             showNum.spriteName = number[i].ToString();
25         }
26 
27         scoreGrid.Reposition();
28         scoreGrid.repositionNow = true;
29     }

 

2015-4-27 

用上面的方法删除所有子物体 Edit模式 不行,试试用下面的方法,可能是 Edit模式 下删除子物体 的时候引发了重新内部元素排序。暂时还没有测试 Run 模式

1 List<Transform> list = new List<Transform>();
2 foreach (Transform item in transform)
3 {
4     list.Add(item);
5 }
6 foreach (var item in list)
7 {
8     NGUITools.Destroy(item.gameObject);
9 }

 

转载于:https://www.cnblogs.com/chongxin/p/4253187.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值