【发布时间】:2018-09-13 20:14:29
【问题描述】:
我正在我的游戏中创建一个商店来购买虚拟商品。
主商店页面
每个组都有自己的项目。我创建了一个视图,每次只有一个项目可见,并带有用于转到上一个和下一个项目的按钮。
特定组选择菜单 - 团队
问题是我不知道如何在最后一个窗口中显示我拥有项目的列表,并使其触摸列表上一个/下一个按钮显示不同的项目。
列表中的每个项目都称为inventory[x](x = 循环中的数字)并具有属性itemName 和itemDescription。
如何使代码与图形用户界面通信?
我创建了 6 个库存列表(每个列表对应一种可解锁的虚拟商品),并且我使用 GameSparks API 来提供在线功能,例如玩家资料。
列表在脚本开头声明:
public static List<Inventario> inventarioEquipos = new List<Inventario>(); //Inventory for Teams
public static List<Inventario> inventarioPelotas = new List<Inventario>(); //Inventory for Balls
public static List<Inventario> inventarioModos = new List<Inventario>(); //Inventory for Modes
public static List<Inventario> inventarioVitores = new List<Inventario>(); //Inventory for Cheers
public static List<Inventario> inventarioCampos = new List<Inventario>(); //Inventory for Fields
public static List<Inventario> inventarioFondos = new List<Inventario>(); //Inventory for Backgrounds
在我调用的 Awake 方法中:
Info_Botones ("Equipos"); //I call this function for each group, to load its items and show how many items of a total of X the player owns. If you look at the first picture, will see below TEAMS: 1/2. That's what this function is for (besides to load all the unlockables in separated lists).
Info_Botones ("Pelotas");
Info_Botones ("Modos");
Info_Botones ("Vitores");
Info_Botones ("Campos");
Info_Botones ("Fondos");
main函数代码如下:
private void Info_Botones(string tipoDeInventario) { //"tipoDeInventario" means InventoryType and I use it to pass to the function which type of inventory I want to load (Teams, Balls, Modes, Cheers, Fields or Backgrounds)
int numero = 0;
new LogEventRequest()
.SetEventKey("INVENTARIO")
.SetEventAttribute("TAG_TYPE", tipoDeInventario)
.Send((response) =>
{
if (!response.HasErrors)
{
List<object> entryList = response.ScriptData.GetObjectList("result") as List<object>;
for (int i = 0; i < entryList.Count; i++)
{
Dictionary<string, object> entry = entryList[i] as Dictionary<string, object>;
int itemId = i;
string itemName = (entry["name"]).ToString();
string itemDescription = (entry["description"]).ToString();
int itemPrice = int.Parse((entry["currency1Cost"].ToString()));
string itemInteractable = (entry["interactable"]).ToString();
Inventario inv = new Inventario(itemId, itemName, itemDescription, itemPrice, itemInteractable);
if(tipoDeInventario == "Equipos") {
inventarioEquipos.Add(inv);
if (inventarioEquipos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Pelotas") {
inventarioPelotas.Add(inv);
if (inventarioPelotas[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Modos") {
inventarioModos.Add(inv);
if (inventarioModos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Vitores") {
inventarioVitores.Add(inv);
if (inventarioVitores[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Campos") {
inventarioCampos.Add(inv);
if (inventarioCampos[i].itemInteractable == "False") {
numero++;
}
} else if(tipoDeInventario == "Fondos") {
inventarioFondos.Add(inv);
if (inventarioFondos[i].itemInteractable == "False") {
numero++;
}
} else {
}
}
if(tipoDeInventario == "Equipos") {
txtBtnCantidadEquipos.text = numero.ToString() + "/" + inventarioEquipos.Count;
} else if(tipoDeInventario == "Pelotas") {
txtBtnCantidadPelotas.text = numero.ToString() + "/" + inventarioPelotas.Count;
} else if(tipoDeInventario == "Modos") {
txtBtnCantidadModos.text = numero.ToString() + "/" + inventarioModos.Count;
} else if(tipoDeInventario == "Vitores") {
txtBtnCantidadVitores.text = numero.ToString() + "/" + inventarioVitores.Count;
} else if(tipoDeInventario == "Campos") {
txtBtnCantidadCampos.text = numero.ToString() + "/" + inventarioCampos.Count;
} else if(tipoDeInventario == "Fondos") {
txtBtnCantidadFondos.text = numero.ToString() + "/" + inventarioFondos.Count;
} else {
}
}
else
{
Debug.Log("ERROR AL OBTENER VG DEL JUGADOR: " + response.Errors.JSON);
}
});
}
【问题讨论】:
-
你能贴一张你想要完成的模型图片吗? GUI 应该是什么样的?我很难理解你想要做什么。我清理了您帖子中的语法,但我不确定这句话是什么意思:“问题是我不知道如何在最后一个窗口中显示我拥有项目的列表并使其触摸按钮上一个/下一个列表显示不同的项目。"
-
嗨!谢谢回答。您在最后一张图片中看到的“Equipo Argentina”文本是 LIST 中第一项的名称。我希望当我触摸 NEXT 按钮时,它将列表中第一项的信息替换为列表中第二项的信息......等等。我希望它循环(当用户触摸最后一项中的 NEXT 按钮时,它应该再次显示 LIST 的第一个)。与 PREVIOUS 按钮相反。它应该倒退(从第 5 项到第 4 项,再到第 3 项……)。感谢您的宝贵时间,对不起我的英语水平;)
-
你所问的听起来很容易做到。但是,我有必要知道您的
inventory列表是什么样的。 -
我已经用代码更新了主帖。谢谢你的时间! :)
标签: c# user-interface unity3d interface inventory