예제 #1
0
    void LoadData(string _levelName)
    {
        StreamReader path = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, fileName));

        Debug.Log(Application.persistentDataPath);
        //Debug.Log(path);
        string loadJson = path.ReadToEnd();

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

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

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

        //驗證用,將sammaru的位置變更為json內紀錄的位置

        switch (_levelName)
        {
        //****************Animal****************
        case "Animal1":
            if (loadData.Animal1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Animal1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Animal1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Animal2":
            if (loadData.Animal2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Animal2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Animal2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Animal3":
            if (loadData.Animal3_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Animal3_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Animal3_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Cuisime********************************
        case "Cuisime1":
            if (loadData.Cuisime1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Cuisime1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Cuisime1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Cuisime2":
            if (loadData.Cuisime2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Cuisime2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Cuisime2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Fruit********************************
        case "Fruit1":
            if (loadData.Fruit1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Fruit1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Fruit1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Fruit2":
            if (loadData.Fruit2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Fruit2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Fruit2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Meat********************************
        case "Meat1":
            if (loadData.Meat1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Meat1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Meat1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Vegetable********************************
        case "Vegetable1":
            if (loadData.Vegetable1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Vegetable1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Vegetable1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Vegetable2":
            if (loadData.Vegetable2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Vegetable2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Vegetable2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************MakeUp********************************
        case "MakeUp1":
            if (loadData.MakeUp1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.MakeUp1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.MakeUp1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Position********************************
        case "Position1":
            if (loadData.Position1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Position1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Position1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Position2":
            if (loadData.Position1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Position2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Position2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Position3":
            if (loadData.Position3_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Position3_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Position3_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************EleProducts********************************
        case "EleProducts1":
            if (loadData.EleProducts1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.EleProducts1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.EleProducts1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Family********************************
        case "Family1":
            if (loadData.Family1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Family1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Family1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Transport********************************
        case "Transport1":
            if (loadData.Transport1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Transport1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Transport1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Festival********************************
        case "Festival1":
            if (loadData.Festival1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Festival1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Festival1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Subject********************************
        case "Subject1":
            if (loadData.Subject1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Subject1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Subject1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************CuisimeStyle********************************
        case "CuisimeStyle1":
            if (loadData.CuisimeStyle1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.CuisimeStyle1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.CuisimeStyle1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Hair********************************
        case "Hair1":
            if (loadData.Hair1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Hair1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Hair1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Fitting********************************
        case "Fitting1":
            if (loadData.Fitting1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Fitting1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Fitting1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Weather********************************
        case "Weather1":
            if (loadData.Weather1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Weather1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Weather1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Stationery********************************
        case "Stationery1":
            if (loadData.Stationery1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Stationery1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Stationery1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Clothes********************************
        case "Clothes1":
            if (loadData.Clothes1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Clothes1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Clothes1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Shoes********************************
        case "Shoes1":
            if (loadData.Shoes1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Shoes1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Shoes1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Colors********************************
        case "Colors1":
            if (loadData.Colors1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Colors1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Colors1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Disaster********************************
        case "Disaster1":
            if (loadData.Disaster1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Disaster1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Disaster1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Beverage********************************
        case "Beverage1":
            if (loadData.Beverage1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Beverage1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Beverage1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Facility********************************
        case "Facility1":
            if (loadData.Facility1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Facility1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Facility1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Plant********************************
        case "Plant1":
            if (loadData.Plant1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Plant1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Plant1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Career********************************
        case "Career1":
            if (loadData.Career1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Career1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Career1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Career2":
            if (loadData.Career2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Career2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Career2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Body********************************
        case "Body1":
            if (loadData.Body1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Body1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Body1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Body2":
            if (loadData.Body2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Body2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Body2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Sport********************************
        case "Sport1":
            if (loadData.Sport1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Sport1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Sport1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Sport2":
            if (loadData.Sport2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Sport2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Sport2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Contry********************************
        case "Contry1":
            if (loadData.Contry1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Contry1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Contry1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Contry2":
            if (loadData.Contry2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Contry2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Contry2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        //************************Furniture********************************
        case "Furniture1":
            if (loadData.Furniture1_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Furniture1_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Furniture1_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;

        case "Furniture2":
            if (loadData.Furniture2_Temp.Count != 0)
            {
                for (int i = 0; i < loadData.Furniture2_Temp.Count; i++)
                {
                    tempListString.Add(loadData.Furniture2_Temp[i]);
                    //Debug.Log(tempListString[i]);
                }
            }
            else
            {
                for (int i = 0; i < answerInput.Count; i++)
                {
                    tempListString.Add("");
                }
            }
            break;
        }
        for (int i = 0; i < answerInput.Count; i++)
        {
            if (tempListString[i] != null)
            {
                answerInput[i].GetComponent <InputField>().text = tempListString[i];
                GetAnswerInt(i);
            }
        }
    }
예제 #2
0
    void ClearJson()
    {
        string filePath = Application.persistentDataPath + "/" + fileName;

        if (File.Exists(filePath))
        {
            StreamReader path = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, fileName));
            //Debug.Log(Application.persistentDataPath);
            //Debug.Log(path);
            string loadJson = path.ReadToEnd();
            Debug.Log(loadJson);
            path.Close();

            OnlyStringData loadData = JsonUtility.FromJson <OnlyStringData>(loadJson);

            loadData.Animal1_Temp.Clear();
            loadData.Animal2_Temp.Clear();
            loadData.Animal3_Temp.Clear();
            loadData.Cuisime1_Temp.Clear();
            loadData.Cuisime2_Temp.Clear();
            loadData.Fruit1_Temp.Clear();
            loadData.Fruit2_Temp.Clear();
            loadData.MakeUp1_Temp.Clear();
            loadData.Meat1_Temp.Clear();
            loadData.Vegetable1_Temp.Clear();
            loadData.Vegetable2_Temp.Clear();

            loadData.MakeUp1_Temp.Clear();
            loadData.Position1_Temp.Clear();
            loadData.Position2_Temp.Clear();
            loadData.Position3_Temp.Clear();
            loadData.EleProducts1_Temp.Clear();
            loadData.Clothes1_Temp.Clear();
            loadData.Contry1_Temp.Clear();
            loadData.Contry2_Temp.Clear();
            loadData.Family1_Temp.Clear();
            loadData.Transport1_Temp.Clear();
            loadData.Festival1_Temp.Clear();
            loadData.Subject1_Temp.Clear();
            loadData.Hair1_Temp.Clear();
            loadData.Fitting1_Temp.Clear();
            loadData.Body1_Temp.Clear();
            loadData.Body2_Temp.Clear();
            loadData.Weather1_Temp.Clear();
            loadData.Dessert1_Temp.Clear();
            loadData.Dessert2_Temp.Clear();
            loadData.Dessert3_Temp.Clear();
            loadData.Stationery1_Temp.Clear();
            loadData.Shoes1_Temp.Clear();
            loadData.Colors1_Temp.Clear();
            loadData.Beverage1_Temp.Clear();
            loadData.Facility1_Temp.Clear();
            loadData.Sport1_Temp.Clear();
            loadData.Sport2_Temp.Clear();
            loadData.Disaster1_Temp.Clear();
            loadData.Plant1_Temp.Clear();
            loadData.Career1_Temp.Clear();
            loadData.Career2_Temp.Clear();
            loadData.Furniture1_Temp.Clear();
            loadData.Furniture2_Temp.Clear();


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

            StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, fileName));
            Debug.Log(file.ToString());
            file.Write(contents);
            file.Close();


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

            Debug.Log("SAVE");
        }
    }