纳金网

标题: Unity3D教程:动态添加删除iGUI的控件 [打印本页]

作者: 妮妮和娃娃    时间: 2013-6-17 17:50
标题: Unity3D教程:动态添加删除iGUI的控件
本帖最后由 妮妮和娃娃 于 2013-6-17 17:51 编辑

在iGUI中,Enable=false可以看不到控件,但是没有去除,Unity如何动态添加删除iGUI控件呢?

1.添加:iGUI.iGUIRoot.addElement(“iGUIProgressBar”);

2.去除:iGUI.iGUIRoot.removeElement(iGUI.iGUIElement);

下面看看我的例子吧:

01
[java] view plaincopyprint?
02

03
<pre class=“html” name=“code”>var root:iGUI.iGUIRoot;
04

05
var chun:iGUI.iGUIProgressBar;
06

07
function OnGUI() {
08

09
if(GUI.Button(Rect(0,0,100,100),“add”)){
10

11
chun=root.addElement(“iGUIProgressBar”);//必须写iGUIxxx;
12

13
chun.name=“chun”;
14

15
}  
16

17
if(GUI.Button(Rect(0,110,100,100),“remove”)){
18

19
root.removeElement(chun);//必须没有“”,要不然报错的。
20

21
}
22

23
}</pre><br>
24

25
<pre></pre>
26

27
<p> <span style=“color:#ff0000”> 注:removeElement的chun是</span><span style=“background-color:rgb(255,255,255)”><span style=“color:#ff0000”>var chun:iGUI.iGUIProgressBar;里面的chun,而不是chun.name=“chun”;</span></span></p>
28

29
<p></p>
30

31
<p>我以前不会改变iGUIProgressBar的height,后来发现应该把Empty Style和Fill Style的-->Fixed Height改成0就可以了~~~</p>
32

33
<pre></pre>


转载请标明文章来源:unity3d论坛


作者: 狂风大尉    时间: 2013-6-18 01:02
thanks for sharing!
作者: 艾西格亚    时间: 2013-6-27 15:29
感谢分享技术教程!
作者: 幸福小猪    时间: 2013-10-28 10:28
感谢楼主分享~
作者: 幸福小猪    时间: 2013-10-28 10:32
感谢楼主分享~
作者: xizhenlong    时间: 2015-1-21 16:34
我还是习惯用NGUI做啊   




欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5