0
一個DropDownList我是新來的團結,所以我不知道如何在運行時創建Unity3d一個DropDownList如何在運行時創建的unity3d
我能夠創建列表中多次現場載荷爲每例在下面給出鏈接http://wiki.unity3d.com/index.php?title=PopupList
但我不知道如何在運行時創建這些,我已經嘗試創建這個類。
#pragma strict
class CustomList extends MonoBehaviour
{
var title:String;
var top:int;
var left:int;
var width:int;
var height:int;
private var listEntry = 0;
private var list : GUIContent[];
private var listStyle : GUIStyle;
private var showList = false;
public function CustomList(title:String,top:int,left:int,width:int,height:int){
this.title = title;
this.top=top;
this.left = left;
this.width = width;
this.height = height;
list = new GUIContent[1];
list[0] = new GUIContent("Granite");
// Make a GUIStyle that has a solid white hover/onHover background to indicate highlighted items
listStyle = new GUIStyle();
listStyle.normal.textColor = Color.white;
var tex = new Texture2D(2, 2);
var colors = new Color[4];
for (color in colors) color = Color.white;
tex.SetPixels(colors);
tex.Apply();
listStyle.hover.background = tex;
listStyle.onHover.background = tex;
listStyle.padding.left = listStyle.padding.right = listStyle.padding.top = listStyle.padding.bottom = 4;
}
function Start() {
}
function OnGUI() {
Debug.Log("title for list is : "+title);
GUI.Label (Rect(10, 10, 100, 10), "You picked !");
if (Popup.List (Rect(top, left, width, height), showList, listEntry, GUIContent(this.title), list, listStyle)) {
GUI.Label (Rect(200, 70, 400, 20), "You picked !");
}
}
}
,但我不能將其添加到我的for循環如下
for(var objCategory:Category in objCategoryList.listCategory){
new CustomList(objCategory.categoryName,100,ctr*100,100,20);
ctr++;
}
任何人都可以提出什麼是錯此代碼段中,哪些是在JavaScript這樣做的正確方法unity3d。