Esempio n. 1
0
 void Start()
 {
     AddData = GameObject.Find("Manager").GetComponent <AddPicture>();
     //輸出路徑
     print(System.IO.Path.Combine(Application.persistentDataPath, "test"));
     //心智測驗json
     if (File.Exists(System.IO.Path.Combine(Application.persistentDataPath, "test")))
     {
         print("file exist");
     }
     else
     {
         print("file not exist");
         playerState_test myPlayer1  = new playerState_test();
         string           saveString = JsonUtility.ToJson(myPlayer1);
         StreamWriter     file       = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "test"));
         file.Write(saveString);
         file.Close();
     }
     //拼圖json
     if (File.Exists(System.IO.Path.Combine(Application.persistentDataPath, "puzzle")))
     {
         print("file exist");
     }
     else
     {
         print("file not exist");
         playerState_puzzle myPlayer1  = new playerState_puzzle();
         string             saveString = JsonUtility.ToJson(myPlayer1);
         StreamWriter       file       = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "puzzle"));
         file.Write(saveString);
         file.Close();
     }
 }
Esempio n. 2
0
    public void save_puzzle(TimeSpan timespan, String path)
    {
        //開啟檔案位置
        StreamReader file = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, "puzzle"));
        //讀取檔案
        string loadJson = file.ReadToEnd();

        file.Close();
        playerState_puzzle loadData = new playerState_puzzle();

        //將string 轉為 Json格式
        loadData = JsonUtility.FromJson <playerState_puzzle>(loadJson);
        playerState_puzzle myPlayer1 = new playerState_puzzle();

        myPlayer1 = loadData;
        DateTime Now = DateTime.Now;

        //使用 . Add功能加入
        myPlayer1.realtime_year.Add(Now.Year);
        myPlayer1.realtime_month.Add(Now.Month);
        myPlayer1.realtime_day.Add(Now.Day);
        myPlayer1.cost_time_hour.Add(timespan.Hours);
        myPlayer1.cost_time_min.Add(timespan.Minutes);
        myPlayer1.cost_time_sec.Add(timespan.Seconds);
        myPlayer1.image_path.Add(path);
        myPlayer1.puzzle_row.Add(AddData.row);
        myPlayer1.puzzle_column.Add(AddData.column);
        //將Json 轉為 string
        string saveString = JsonUtility.ToJson(myPlayer1);
        //寫入檔案
        StreamWriter file1 = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "puzzle"));

        file1.Write(saveString);
        file1.Close();
    }
Esempio n. 3
0
    public void load_test_data()
    {
        StreamReader file     = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, "puzzle"));
        string       loadJson = file.ReadToEnd();

        file.Close();
        playerState_puzzle loadData = new playerState_puzzle();

        loadData  = JsonUtility.FromJson <playerState_puzzle>(loadJson); //loadData是整理過後的最終資料
        myPlayer1 = loadData;
        page      = 0;
        drawPic(0);
    }