从列表到图形界面

From List to Graphical Interface

我正在我的游戏中创建一个商店来购买虚拟商品。

主商店页面

每个组都有自己的项目。我创建了一个视图,每次只能看到一个项目,并带有转到上一个和下一个项目的按钮。

特定组选择菜单 - 团队

问题是我不知道如何显示 list 我有项目的地方,在最后一个 window 中并使它触摸按钮 previous/next 列表显示了不同的项目。

列表中的每个项目称为 inventory[x]x = 循环中的数字)并具有属性 itemNameitemDescription

如何让代码与图形用户界面进行通信?

我创建了 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);
                }
            });

}

我已经使用 IF 条件实现了它。如果有人需要代码,请索取,我会分享(我现在不在家)。

谢谢!