예제 #1
0
    void setVolume(string Name, AudioSource audio)
    {
        volumeState myVlume = new volumeState();

        myVlume.volume = audio.volume;
        //將myPlayer轉換成json格式的字串
        string saveString = JsonUtility.ToJson(myVlume);
        //將字串saveString存到硬碟中
        StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, Name));

        file.Write(saveString);
        file.Close();
    }
예제 #2
0
    void updatevolumeState()
    {
        volumeState mySong1 = new volumeState();

        mySong1.volume = 1;
        //將myPlayer轉換成json格式的字串
        string saveString = JsonUtility.ToJson(mySong1);
        //將字串saveString存到硬碟中
        var mySongName = songName + " Audio";
//#if UNITY_EDITOR
        //System.IO.StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.streamingAssetsPath, mySongName));
//#elif UNITY_ANDROID
        StreamWriter file = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, mySongName));

//#endif
        file.Write(saveString);
        file.Close();
    }
예제 #3
0
        public void loadVolume(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);
            //var filePath = Application.persistentDataPath + "/" +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
            Life = 2000;
            //新增一個物件類型為playerState的變數 loadData
            volumeState loadData = new volumeState();

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

            //驗證用,將sammaru的位置變更為json內紀錄的位置
            volume = loadData.volume;
        }
예제 #4
0
    void setVolume()
    {
        string name;

        name = transform.name;
        for (int i = 1; i <= songList.Length; i++)
        {
            if (string.Compare(songList[i - 1], name) == 0)
            {
                listNumber = i;
                name       = "song" + listNumber.ToString("D3");
                Debug.Log("songName: " + name);
                break;
            }
        }
        string txtName;

        txtName = name + " Audio";
        Debug.Log("txtName " + txtName);
        volumeState myVlume = new volumeState();

        myVlume.volume = audioBgm.volume;
        //將myPlayer轉換成json格式的字串
        string saveString = JsonUtility.ToJson(myVlume);

        //將字串saveString存到硬碟中
        #if UNITY_EDITOR
        string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, txtName);
        Debug.Log("filePath:" + filePath);
#elif UNITY_ANDROID
        string filePath = Path.Combine("jar:file://" + Application.dataPath + "!assets/", txtName);
#endif

        StreamWriter file = new StreamWriter(filePath);
        file.Write(saveString);
        file.Close();
    }