Ejemplo n.º 1
0
    void updateMaxScore(int score)
    {
        songState mySong = new songState();

        mySong.name  = songName;
        mySong.score = score;
        //將myPlayer轉換成json格式的字串
        string saveString = JsonUtility.ToJson(mySong);
        //將字串saveString存到硬碟中
        StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.streamingAssetsPath, songName));

        file.Write(saveString);
        file.Close();
    }
Ejemplo n.º 2
0
    public void load()
    {
        //讀取json檔案並轉存成文字格式
        StreamReader file     = new StreamReader(System.IO.Path.Combine(Application.streamingAssetsPath, songName));
        string       loadJson = file.ReadToEnd();

        file.Close();

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

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

        //驗證用,將sammaru的位置變更為json內紀錄的位置
        score = loadData.score;
    }
Ejemplo n.º 3
0
    public void load()
    {
        string loadJson;

        //讀取json檔案並轉存成文字格式
#if UNITY_EDITOR
        string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, songName);
        Debug.Log("filePath:" + filePath);
#elif UNITY_ANDROID
        //string filePath = Path.Combine("jar:file://" + Application.dataPath + "!assets/", songName);
        StreamReader file = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, songName));
#endif

#if UNITY_EDITOR
        StreamReader file = new StreamReader(filePath);
        if (file != null)
        {
            loadJson = file.ReadToEnd();
            file.Close();
            isFull = false;
        }
#elif UNITY_ANDROID
        if (file != null)
        {
            loadJson = file.ReadToEnd();
            file.Close();
            isFull = false;
        }

        /*WWW reader = new WWW (filePath);
         * while (!reader.isDone) {
         * }
         * loadJson = reader.text;*/
#endif

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

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

        //驗證用,將sammaru的位置變更為json內紀錄的位置
        myBestScore = loadData.score;
    }
Ejemplo n.º 4
0
    void updateMaxScore(int score)
    {
        songState mySong = new songState();

        mySong.name  = songName;
        mySong.score = score;
        //將myPlayer轉換成json格式的字串
        string saveString = JsonUtility.ToJson(mySong);
        //將字串saveString存到硬碟中
//#if UNITY_EDITOR
        // StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.streamingAssetsPath, songName));
//#elif UNITY_ANDROID
        StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, songName));

//#endif

        file.Write(saveString);
        file.Close();
    }
Ejemplo n.º 5
0
    public void load()
    {
        string loadJson;
        //讀取json檔案並轉存成文字格式
//#if UNITY_EDITOR
        // string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, songName);
        // Debug.Log("filePath:" + filePath);
//#elif UNITY_ANDROID
        StreamReader file = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, songName));

//#endif

/*#if UNITY_EDITOR
 *      StreamReader file = new StreamReader(filePath);
 *      if(file != null)
 *      {
 *          Debug.Log("not null");
 *          loadJson = file.ReadToEnd();
 *      file.Close();
 *      isFull = false;
 *      }*/

//#elif UNITY_ANDROID

        loadJson = file.ReadToEnd();
        file.Close();
        isFull = false;
//#endif

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

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

        //驗證用,將sammaru的位置變更為json內紀錄的位置
        myBestScore = loadData.score;
    }