示例#1
0
    void SaveData()
    {
        //theWords.tempList.Clear();

        TempDataList tempDataList = new TempDataList();

        for (int i = 0; i < finalCorrentList.Count; i++)
        {
            WordList endList = new WordList();
            //tempList.chinese = finalCorrentList[i].chinese;
            endList.japanese = finalCorrentList[i].japanese;
            endList.status   = finalCorrentList[i].status;

            tempDataList.tempList.Add(endList);
        }

        string contents = JsonUtility.ToJson(tempDataList, true);

        StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, fileName));

        Debug.Log(file.ToString());
        file.Write(contents);
        file.Close();

#if UNITY_EDITOR
        UnityEditor.AssetDatabase.Refresh();
#endif

        Debug.Log("SAVE");
    }
示例#2
0
    void LoadData()
    {
        StreamReader path = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, fileName));

        Debug.Log(path);
        string loadJson = path.ReadToEnd();

        Debug.Log(loadJson);
        path.Close();

        //新增一個物件類型為playerState的變數 loadData
        TempDataList loadData = new TempDataList();

        //使用JsonUtillty的FromJson方法將存文字轉成Json
        loadData = JsonUtility.FromJson <TempDataList>(loadJson);

        //驗證用,將sammaru的位置變更為json內紀錄的位置
        for (int i = 0; i < loadData.tempList.Count; i++)
        {
            finalQuestion.Add(loadData.tempList[i]);
            Debug.Log(finalQuestion[i].chinese);
        }

        maxNumber = finalQuestion.Count;

        if (finalQuestion != null)
        {
            if (iTeam == 3 || iTeam == 6)
            {
                for (int i = 0; i < finalQuestion.Count; i++)
                {
                    if (finalQuestion[i].status == 0)
                    {
                        wordsControll.GetWordString(maxNumber, levelType, finalQuestion[i].japanese, finalQuestion[i].chinese, rightColor);
                    }
                    else
                    {
                        wordsControll.GetWordString(maxNumber, levelType, finalQuestion[i].japanese, finalQuestion[i].chinese, wrongColor);
                    }
                }
            }
        }

        if (iTeam == 2 || iTeam == 5)
        {
            LoadImages();
            if (finalSprites != null)
            {
                for (int i = 0; i < finalQuestion.Count; i++)
                {
                    for (int j = 0; j < finalSprites.Count; j++)
                    {
                        if (finalQuestion[i].japanese == finalSprites[j].name)
                        {
                            if (finalQuestion[i].status == 0)
                            {
                                wordsControll.GetWordString(maxNumber, levelType, finalQuestion[i].japanese, finalQuestion[i].chinese, finalSprites[j], rightColor);
                            }
                            else
                            {
                                wordsControll.GetWordString(maxNumber, levelType, finalQuestion[i].japanese, finalQuestion[i].chinese, finalSprites[j], wrongColor);
                            }
                        }
                    }
                }
            }
        }
    }