PlayPrefs 값을 편집하는 편집기 확장
8244 단어 Unity
코드
다음 코드는 Assets/Editor 하위 등에 저장됩니다.
EditPlayerPrefs.csusing 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);
}
}
}
}
사용법
PrefInfo[]keys 값을 적절하게 변경합니다.
[Window] - [Edit PlayProefs]에서 시작
Reference
이 문제에 관하여(PlayPrefs 값을 편집하는 편집기 확장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/snaka/items/37315d5eb47368a6bf56
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
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);
}
}
}
}
PrefInfo[]keys 값을 적절하게 변경합니다.
[Window] - [Edit PlayProefs]에서 시작
Reference
이 문제에 관하여(PlayPrefs 값을 편집하는 편집기 확장), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/snaka/items/37315d5eb47368a6bf56텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)