unity 编辑器存档_Unity编辑器扩展之存储数据

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,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值