goback add

unity动态添加删除iGUI的控件

2695 点击·0 回帖
灯火互联
楼主

在iGUI中,Enable=false可以看不到控件,但是没有去除,我今天和大家说说unity动态添加删除iGUI控件。
      1.添加:iGUI.iGUIRoot.addElement("iGUIProgressBar");
      2.去除:iGUI.iGUIRoot.removeElement(iGUI.iGUIElement);
下面看看我的例子吧:

[java]
<pre class="html" name="code">var root:iGUI.iGUIRoot;
var chun:iGUI.iGUIProgressBar;
function OnGUI() {
   if(GUI.Button(Rect(0,0,100,100),"add")){
     chun=root.addElement("iGUIProgressBar");//必须写iGUIxxx;
     chun.name="chun";
    }
   if(GUI.Button(Rect(0,110,100,100),"remove")){
     root.removeElement(chun);//必须没有“”,要不然报错的。
       }  
}
   注:removeElement的chun是var chun:iGUI.iGUIProgressBar;里面的chun,而不是chun.name="chun";
我以前不会改变iGUIProgressBar的height,后来发现应该把Empty Style和Fill Style的-->Fixed Height改成0就可以了~~~





喜欢0 评分0