// Use this for initialization private void Awake() { ApplyLocalize(); //Localize text //Load the software volume //保存された音量の読み込み Dictionary <string, int> pref = null; if (saveVolume) { pref = XPlayerPrefs.GetDictionary <string, int>(SaveKey); //nothing -> null //無いとき=null; } foreach (var item in items) { dic[item.key] = item; //Register in dictionary with key //キーで辞書に登録 initVolumes[item.key] = item.volume; //Save the value of inspector at startup //起動時のインスペクタをデフォとする //Update stored saved volume //保存された音量があったら更新 if (pref != null && pref.ContainsKey(item.key)) { item.volume = pref[item.key]; } SetVolume(item.key, item.volume); } }
// Use this for initialization private void Start() { //Load the software volume Dictionary <string, int> pref = null; if (saveVolume) { pref = XPlayerPrefs.GetDictionary <string, int>(SaveKey); //nothing -> null } foreach (var item in items) { dic[item.key] = item; initVolumes[item.key] = item.volume; //Save the value of inspector at startup if (pref != null && pref.ContainsKey(item.key)) { item.volume = pref[item.key]; } SetVolume(item.key, item.volume); } }
/// <summary> /// Generate and return elements saved in JSON format (string type) in PlayerPrefs as Param class. ///(*) Param class is basically the same as a dictionary, and it is the same as XPlayerPrefs.GetDictionary(), because content classes (which inherit Dictionary) are handled easily. ///・In JSON, the dictionary is also saved as a key array and a value array, so XPlayerPrefs.SetArrayPair() saved pair array can also be acquired as a dictionary. /// /// PlayerPrefs に JSON 形式(文字列型)で保存された要素を辞書として生成して返す ///※Param は基本的に辞書と同じでパラメタを簡単に扱うクラス(Dictionary を継承している)ため、内容的には XPlayerPrefs.GetDictionary() と同じ。 ///・JSON では辞書もキー配列と値配列として保存されるため、XPlayerPrefs.SetArrayPair() 保存したペア配列も辞書として取得できる。 /// </summary> /// <param name="key">Save key</param> /// <param name="def">Defalut value</param> /// <returns>Saved value (Param: newly created)</returns> public static Param GetPlayerPrefs(string key, Param def = null) { Dictionary <string, string> dic = XPlayerPrefs.GetDictionary <string, string>(key); return((dic != null) ? new Param(dic) : def); }