Unity 误删 EditorPrefs 数据

今天在学习Unity 编辑器相关知识的时候,手误将 EditorPrefs.DeleteKey删除了一下,导致unity每次启动都会提示布局错误,我尝试着重新下载 安装了Unity,但是还是没有效果。

错误提示:

 实际上我的E盘并没有存放和Unity相关的资源,所以一直也找不到如何处理这个问题。

Failed to load window layout: System.NullReferenceException: Object reference not set to an instance of an object
  at UnityEditor.ContainerWindow.Show (UnityEditor.ShowMode showMode, System.Boolean loadPosition, System.Boolean displayImmediately, System.Boolean setFocus) [0x000f8] in E:\unity\Editor\Mono\ContainerWindow.cs:143 
  at UnityEditor.WindowLayout.LoadWindowLayout (System.String path, System.Boolean newProjectLayoutWasCreated) [0x003c7] in E:\unity\Editor\Mono\GUI\WindowLayout.cs:607 
UnityEditor.WindowLayout:LoadWindowLayout(String, Boolean) (at E:/unity/Editor/Mono/GUI/WindowLayout.cs:617)

 解决方法一:

错误如下图所示:点那个都不好用

        ①关闭HUB,关闭Unity相关程序。

        ②删除 C:/Users/YourUserName\AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts\default\LastLayout.dwlt 文件

        ③打开Unity HUB——在项目处右键——在资源管理器打开——找到Library文件夹全部删除,退出HUB,重启即可。

解决方法二:

有人说 World 项目很,加载Library时要忍很多下,很耗时,有不用删除文件夹的办法嘛?

有!前提是你可以加载Unity默认的布局,仅是每次进项目都会提示布局错误,仅仅是提示而已,但是强迫症的你不允许出现这种情况

        方法①:找到其他没有问题的项目,在资源管理器中查看——找到\Library\CurrentLayout-default.dwlt ——复制替换到你现在有问题的项目中,退出所有Unity相关程序,重启即可。

        方法②:如视频所示

Unity EditorPrefs 慎重使用

                第一步:导航到 C:\Users\YourUserName\AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts 用记事本的方式打开LastLayout.dwlt 文件,全选、复制全部数据

                第二步:导航到项目\Library文件夹内,以记事本的方式打开 CurrentLayout.dwlt 文件,全选、清空文本。将上一步复制的数据粘贴到 CurrentLayout.dwlt 内,保存、重启即可。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是示例代码: ```csharp public static class EditorPrefsHelper { private const string SAVE_PATH_KEY = "SavePath"; private const string SERVER_PATH_KEY = "ServerPath"; private const string BUNDLE_OPTIONS_KEY = "BundleOptions"; private const string BUILD_TARGET_KEY = "BuildTarget"; private const string COPY_TO_SERVER_PATH_KEY = "CopyToServerPath"; public static void SaveData(string savePath, string serverPath, BuildAssetBundleOptions bundleOptions, BuildTarget buildTarget, bool copyToServerPath) { EditorPrefs.SetString(SAVE_PATH_KEY, savePath); EditorPrefs.SetString(SERVER_PATH_KEY, serverPath); EditorPrefs.SetInt(BUNDLE_OPTIONS_KEY, (int)bundleOptions); EditorPrefs.SetInt(BUILD_TARGET_KEY, (int)buildTarget); EditorPrefs.SetInt(COPY_TO_SERVER_PATH_KEY, copyToServerPath ? 1 : 0); } public static void LoadData(out string savePath, out string serverPath, out BuildAssetBundleOptions bundleOptions, out BuildTarget buildTarget, out bool copyToServerPath) { savePath = EditorPrefs.GetString(SAVE_PATH_KEY, ""); serverPath = EditorPrefs.GetString(SERVER_PATH_KEY, ""); bundleOptions = (BuildAssetBundleOptions)EditorPrefs.GetInt(BUNDLE_OPTIONS_KEY, 0); buildTarget = (BuildTarget)EditorPrefs.GetInt(BUILD_TARGET_KEY, 0); copyToServerPath = EditorPrefs.GetInt(COPY_TO_SERVER_PATH_KEY, 0) == 1; } } ``` 使用方法: ```csharp // 保存数据 EditorPrefsHelper.SaveData( "Assets/StreamingAssets", "/var/www/html", BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64, true ); // 读取数据 string savePath, serverPath; BuildAssetBundleOptions bundleOptions; BuildTarget buildTarget; bool copyToServerPath; EditorPrefsHelper.LoadData(out savePath, out serverPath, out bundleOptions, out buildTarget, out copyToServerPath); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值