Beispiel #1
0
    void FillTradeItemGrid()
    {
        string recipeID = _focusItem.ttData.tattooID;

        TattooExchangeData exchangeData = DataManager.Instance.tattooExchangeDataList.dataList.Find(delegate(TattooExchangeData ted)
        {
            return(ted.id == recipeID);
        });

        if (PlayerInfo.Instance.SoftCurrency >= exchangeData.costSC)
        {
            labelNeedSC.text = exchangeData.costSC.ToString();
        }
        else
        {
            labelNeedSC.text = string.Format("[ff0000]{0}", exchangeData.costSC);
        }

        int index = 0;

        foreach (MatAmountMapping mapping in exchangeData.materials)
        {
            UITattooMaterialItem uiItem;

            if (index < _tmList.Count)
            {
                uiItem = _tmList[index];
            }
            else
            {
                GameObject go = NGUITools.AddChild(materialGrid.gameObject, materialItemPrefab);

                uiItem = go.GetComponent <UITattooMaterialItem>();

                _tmList.Add(uiItem);
            }

            uiItem.SetData(mapping.materialName, mapping.amount);

            uiItem.gameObject.SetActive(true);

            index++;
        }

        while (index < _tmList.Count)
        {
            _tmList[index++].gameObject.SetActive(false);
        }

        materialGrid.repositionNow = true;
    }
    void FillTradeItemGrid()
    {
        string recipeID = _focusItem.ttData.recipeID;

        TattooExchangeData exchangeData = DataManager.Instance.tattooExchangeDataList.dataList.Find(delegate(TattooExchangeData ted)
        {
            return(ted.id == recipeID);
        });

        int index = 0;

        foreach (MatAmountMapping mapping in exchangeData.materials)
        {
            UITattooMaterialItem uiItem;

            if (index < _tmList.Count)
            {
                uiItem = _tmList[index];
            }
            else
            {
                GameObject go = NGUITools.AddChild(materialGrid.gameObject, materialItemPrefab);

                uiItem = go.GetComponent <UITattooMaterialItem>();

                _tmList.Add(uiItem);
            }

            uiItem.SetData(mapping.materialName, mapping.amount);

            uiItem.gameObject.SetActive(true);

            index++;
        }

        while (index < _tmList.Count)
        {
            _tmList[index++].gameObject.SetActive(false);
        }

        materialGrid.Reposition();
    }
    public static void Read()
    {
        bool newFile = false;

        TattooExchangeDataList dataList = null;

        UnityEngine.Object oldFile = AssetDatabase.LoadAssetAtPath(outFileName, typeof(TattooExchangeDataList));
        if (oldFile == null)
        {
            newFile  = true;
            dataList = ScriptableObject.CreateInstance(typeof(TattooExchangeDataList)) as TattooExchangeDataList;
        }
        else
        {
            dataList = oldFile as TattooExchangeDataList;
        }

        dataList.dataList.Clear();

        string jsonStr = File.ReadAllText(fileName);

        Hashtable ht = FCJson.jsonDecode(jsonStr) as Hashtable;

        foreach (System.Object obj in ht.Values)
        {
            Hashtable ht2 = obj as Hashtable;

            TattooExchangeData newData = new TattooExchangeData();

            newData.id = ht2["item"] as string;

            newData.costSC = (int)ht2["costSC"];

            newData.materials = new List <MatAmountMapping>();

            for (int i = 1; i < 6; i++)
            {
                string fieldMat   = "material" + i.ToString();
                string fieldCount = "count" + i.ToString();

                string materialName = ht2[fieldMat] as string;

                if (string.IsNullOrEmpty(materialName))
                {
                    break;
                }

                newData.materials.Add(new MatAmountMapping(materialName, (int)ht2[fieldCount]));
            }

            dataList.dataList.Add(newData);
        }

        if (newFile)
        {
            AssetDatabase.CreateAsset(dataList, outFileName);
        }
        else
        {
            EditorUtility.SetDirty(dataList);
        }
        Debug.Log(string.Format("Tattoo Exchange data imported OK. {0} records.", dataList.dataList.Count));
    }