Exemple #1
0
    private void DisplayItems()
    {   //Load Data of items
        TextAsset dataAsJson = new TextAsset();

        dataAsJson = Resources.Load <TextAsset>("ItemListJson");
        ItemListDatas allItemListData = new ItemListDatas();

        allItemListData = JsonUtility.FromJson <ItemListDatas>(dataAsJson.text);
        ItemListData[] itemListDatas = allItemListData.itemListDatas;

        itemData = new List <ItemListData>();
        foreach (ItemListData itemListData in itemListDatas)
        {
            itemData.Add(itemListData);
        }

        //Debug_ShowItemDatas(itemData);//for debug use only

        foreach (ItemListData thisItemData in itemData)
        {
            GameObject buttonGameObject = GameObjectUtility.CustomInstantiate(itemButton.gameObject, this.transform);
            Button     btn = buttonGameObject.GetComponent <Button>();
            btn.GetComponentInChildren <Text>().text    = thisItemData.strItemName;
            btn.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>("ItemIcons/" + thisItemData.strItemName);
            ExistingButtons.Add(btn);

            ItemScript itemScript = buttonGameObject.GetComponent <ItemScript>();
            itemScript.Initialize(processor);

            foreach (ItemAttribute itemAttri in thisItemData.itemAttributes)
            {
                itemScript.AddAttribute(itemAttri.key, itemAttri.value);
                foreach (string strExtra in possibleExtras)
                {
                    if (itemAttri.key.Contains(strExtra))
                    {
                        itemScript.AddExtra(itemAttri.key, (int)itemAttri.value);
                    }
                }
            }
            itemScript.item.strName = thisItemData.strItemName;
        }
    }