【Unity开发】NGUI动态刷新ScrollView

来源:互联网 发布:淘宝宝贝七天下架吗 编辑:程序博客网 时间:2024/05/17 16:02
使用NGUI开发ScrollView时,当动态添加Prefab时无法重新排序,

此时可以通过调用UIGrid组件的Reposition()函数来刷新ScrollView
或者通过属性repositionNow = true来刷新
</pre></div><div style="font-family: Arial; font-size: 14px; line-height: 26px;"></div><div style="font-family: Arial; font-size: 14px; line-height: 26px;"><span style="white-space: pre;"></span>具体代码如下:<pre name="code" class="csharp">[csharp] view plain copy 在CODE上查看代码片派生到我的代码片using UnityEngine;  using System.Collections;    public class test : MonoBehaviour {            UIGrid Grid;      // Use this for initialization      void Start () {          //首先获取到UIGrid组件          Grid = GameObject.Find("UIGrid").GetComponent<UIGrid>();      }            void OnGUI()      {          if (GUILayout.Button("刷新"))          {              //两种方法都可行              Grid.repositionNow = true;              Grid.Reposition();          }      }  }  

0 0
原创粉丝点击