void setNote(string Name) { noteState myNote = new noteState(); int playNumber = 3; myNote.noteAudio = notePlayer[playNumber].clip; //將myPlayer轉換成json格式的字串 string saveString = JsonUtility.ToJson(myNote); //將字串saveString存到硬碟中 StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, Name)); file.Write(saveString); file.Close(); }
void setNote(string Name) { noteState myNote = new noteState(); noteNumber = int.Parse(noteNumberText.text); int playNumber = noteNumber - 1; myNote.noteAudio = notePlayer[playNumber].clip; //將myPlayer轉換成json格式的字串 string saveString = JsonUtility.ToJson(myNote); //將字串saveString存到硬碟中 StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.streamingAssetsPath, Name)); file.Write(saveString); file.Close(); }
public void loadNoteAudio(string name) { string loadJson; //讀取json檔案並轉存成文字格式 #if UNITY_EDITOR string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, name); Debug.Log("filePath:" + filePath); #elif UNITY_ANDROID //string filePath = Path.Combine("jar:file://" + Application.dataPath + "!assets/", name); StreamReader file = new StreamReader(System.IO.Path.Combine(Application.persistentDataPath, name)); #endif #if UNITY_EDITOR StreamReader file = new StreamReader(filePath); loadJson = file.ReadToEnd(); file.Close(); #elif UNITY_ANDROID if (file != null) { loadJson = file.ReadToEnd(); file.Close(); } /*WWW reader = new WWW (filePath); * while (!reader.isDone) { * } * loadJson = reader.text;*/ #endif //新增一個物件類型為playerState的變數 loadData noteState loadData = new noteState(); //使用JsonUtillty的FromJson方法將存文字轉成Json loadData = JsonUtility.FromJson <noteState>(loadJson); //驗證用,將sammaru的位置變更為json內紀錄的位置 noteAudio = loadData.noteAudio; }
void setNote(string Name) { noteState myNote = new noteState(); if (string.Compare(noteNumberText.text, "X") == 0) { noteNumber = 5; } else { noteNumber = int.Parse(noteNumberText.text); } int playNumber = noteNumber - 1; myNote.noteAudio = notePlayer[playNumber].clip; //將myPlayer轉換成json格式的字串 string saveString = JsonUtility.ToJson(myNote); //將字串saveString存到硬碟中 StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, Name)); file.Write(saveString); file.Close(); }