-1
我试图在unity3d中实现一个库存系统。他们是几种方法来实现gui上的库存,但我选择了最简单的方法。按下一个按钮,集中所有按钮
gui上的每个项目都表示为单元格(GUI.Button)。每个空单元表示清单中的空白位置(GUI.Box)。当我按下一个按钮选择一个项目时,所有按钮都变得焦点了。
我的问题是为什么会发生这种情况,需要解决哪些问题才能使一个按钮得到聚焦?我创建了一个基于空的GUISkin。感谢您的关注
以下是显示清单的代码。
void OnGUI(){
if (visible) {
GUI.skin = skin;
GUI.Window(0,new Rect((Screen.width-1024)/2,0,1024,600),InventoryBody,"Inventory");
}
}
void InventoryBody(int id){
GUIStyle style = new GUIStyle();
if (currentItem) {
GUI.DrawTexture (new Rect(550f,70f,80f,80f), currentItem.texture);
GUI.color = Color.red;
GUI.Label (new Rect(700f,50f,400f,300f), currentItem.name);
GUI.color = Color.black;
string desc = "Description: "+currentItem.description;
style.wordWrap=true;
style.fontSize=18;
GUI.Label (new Rect(650f,100f,300f,500f), desc,style);
if(GUI.Button(new Rect(700f, 290f, 150f,50f), "Cancel")) {
currentItem = null;
}
if(GUI.Button(new Rect(700f, 230f, 150f,50f), "Use")) {
currentItem.Use();
}
}
//1st column
GUILayout.BeginArea (new Rect (80f,60f,600f,600f));
for (int i = 0; i<5; i++) {
if(items[i]!=null){
if(GUILayout.Button (items [i].texture, GUILayout.Width (80f), GUILayout.Height (80f))){
currentItem = items[i];
}
} else {
GUILayout.Box("", GUILayout.Width(80f),GUILayout.Height(80f));
}
}
GUILayout.EndArea();
//2nd column
GUILayout.BeginAr...
}