我正在游戏内创建一家商店来购买虚拟商品。
每个组都有自己的项目。我创建了一个视图,每次仅可见一个项目,并带有转到上一个和下一个项目的按钮。
问题是,我不知道如何在最后一个窗口中显示列表所在的项目,并且使触摸列表前/后的按钮可以显示不同的项目。
列表中的每个项目都称为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");
主要功能的代码如下:
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);
}
});
}
答案 0 :(得分:0)
我已经使用IF判决实现了这一目标。如果有人需要该代码,请索要该代码,然后我将其共享(我现在不在家)。
谢谢!