EditorPrefs
EditorPrefs可以在PC中存储共享数据,即不受制于项目地存储信息
影响范围
保存的值会影响每一个大版本的Unity编辑器
以前存储在Unity4.x的值只能在Unity 4.x版进行处理,Unity5.x的还可以在Unity 5.x中只处理。
保存什么
应在EditorPrefs存储的窗口的位置和大小,Unity编辑器结构的值等。通过EditorPrefs存储的所有值都以文本形式存储,所以密码等重要信息,请不要保存。
EditorPrefs存储的位置
平台位置
Windows(Unity4.x) HKEY_CURRENT_USER\Software\Unity Technologies\UnityEditor 4.x
Windows(Unity5.x) HKEY_CURRENT_USER\Software\Unity Technologies\UnityEditor 5.x
Mac OS X(Unity4.x) ~/Library/Preferences/com.unity3d.UnityEditor4.x.plist
Mac OS X(Unity5.x) ~/Library/Preferences/com.unity3d.UnityEditor5.x.plist
EditorPrefs为每个主要版本单独保存。Windows将保存在注册表中。如果在Windows通过EditorPrefs存储值,如果出错可能会使Windows无法启动。
当Enable的时候获取保存过的值,在intervalTime改变的时候,保存intervalTime
using UnityEngine;
using UnityEditor;
public class ExampleWindow : EditorWindow
{
int intervalTime = 60;
const string AUTO_SAVE_INTERVAL_TIME = "AutoSave interval time (sec)";
[MenuItem ("Window/Example")]
static void Open ()
{
GetWindow ();
}
void OnEnable ()
{
intervalTime = EditorPrefs.GetInt (AUTO_SAVE_INTERVAL_TIME, 60);
}
void OnGUI ()
{
EditorGUI.BeginChangeCheck ();
//シーン自動保存間隔(秒)
intervalTime = EditorGUILayout.IntSlider ("間隔(秒)", intervalTime, 1, 3600);
if (EditorGUI.EndChangeCheck ())
EditorPrefs.SetInt (AUTO_SAVE_INTERVAL_TIME,