Skip to content

Instantly share code, notes, and snippets.

@snaka
Created July 2, 2014 08:19
Show Gist options
  • Save snaka/b935ffde1aadc248b363 to your computer and use it in GitHub Desktop.
Save snaka/b935ffde1aadc248b363 to your computer and use it in GitHub Desktop.
PlayerPrefs の値を編集するエディタ拡張 ref: http://qiita.com/snaka/items/37315d5eb47368a6bf56
using UnityEngine;
using UnityEditor;
using System.Collections;
public class EditPlayerPrefs : EditorWindow {
class PrefInfo {
public string Key;
public string Type;
}
// 表示対象のキーとタイプ
PrefInfo[] keys = new PrefInfo[] {
new PrefInfo { Key = "hoge", Type = "string" },
new PrefInfo { Key = "fuga", Type = "int" },
};
[MenuItem("Window/Edit PlayerPrefs")]
public static void ShowWindow() {
EditorWindow win = EditorWindow.GetWindow<EditPlayerPrefs>();
win.title = "PlayerPrefs";
}
void OnGUI() {
foreach(var keyInfo in keys) {
switch(keyInfo.Type) {
case "string":
var originalString = PlayerPrefs.GetString(keyInfo.Key);
var currentString = EditorGUILayout.TextField(keyInfo.Key, originalString);
if (currentString != originalString) {
PlayerPrefs.SetString(keyInfo.Key, currentString);
Debug.Log ("*** update " + originalString + " => " + currentString);
}
break;
case "int":
var originalInteger = PlayerPrefs.GetInt (keyInfo.Key);
var currentInteger = System.Convert.ToInt32(EditorGUILayout.TextField(keyInfo.Key, originalInteger.ToString()));
if (currentInteger != originalInteger) {
PlayerPrefs.SetInt(keyInfo.Key, currentInteger);
Debug.Log ("*** update " + originalInteger.ToString() + " => " + currentInteger.ToString());
}
break;
default:
throw new Claris.System.Exception.ApplicationError("Unsupported pref type : " + keyInfo.Type);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment