Unity插件推荐

一、可视化PlayerPrefs

Advanced PlayerPrefs Window插件是一款PlayerPrefs数据的可视化管理插件

下载地址:http://www.taidous.com/forum.php?mod=viewthread&tid=59744&highlight=PlayerPrefs

或者链接:http://pan.baidu.com/s/1bpg0AYF 密码:w9vm

插件界面如下图所示:

这里写图片描述

插件代码分析:

至于编辑器的代码就不解释了,主要来看一下该插件是如何获取到工程里关于PlayerPrefs数据的所有的key 的。
先看一下官方文档中关于PlayerPrefs的解释:
https://docs.unity3d.com/2017.2/Documentation/ScriptReference/PlayerPrefs.html

其中

这里写图片描述

从图中可以看出Unity将这些数据在各平台下存储的位置,以Windows为例,其数据存储在注册表中的

HKCU/Software[company name][product name]中

下面是截图:
这里写图片描述

扫描二维码关注公众号,回复: 889796 查看本文章

图中可见该工程包含了5个key,其中UnityGraphicsQuality是Unity工程自带的。

下面上一段该插件从注册表中获取key的代码(Windows平台的)

        private string[] GetAllWindowsKeys()
        {
            RegistryKey cuKey = Registry.CurrentUser;
            RegistryKey unityKey;

            //The default location of PlayerPrefs pre Unity 5_5
#if UNITY_5_5_OR_NEWER
            unityKey = cuKey.CreateSubKey("Software\\Unity\\UnityEditor\\" + PlayerSettings.companyName + "\\" + PlayerSettings.productName);
#else
            unityKey = cuKey.CreateSubKey("Software\\" + PlayerSettings.companyName + "\\" + PlayerSettings.productName);

            if (unityKey.GetValueNames().Length == 0)
            {
                //On some machines (Windows 7 & 8 64bit using Unity5.4) PlayersPrefs are saved in HKEY_CURRENT_USER\SOFTWARE\AppDataLow\Software\CompanyName\ProjectName weird enough...
                unityKey = cuKey.CreateSubKey("Software\\AppDataLow\\Software\\" + PlayerSettings.companyName + "\\" + PlayerSettings.productName);
            }
#endif

            string[] values = unityKey.GetValueNames();
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = values[i].Substring(0, values[i].LastIndexOf("_"));
            }

            return values;
        }

代码不一一解释了,关于RegistryKey类和Registry类查看一下MSDN:
https://msdn.microsoft.com/zh-cn/library/microsoft.win32.registrykey(v=vs.110).aspx
https://msdn.microsoft.com/zh-cn/library/microsoft.win32.registry(v=vs.110).aspx

以上知识分享,步骤详细,如有错误,欢迎指出,共同学习,共同进步

猜你喜欢

转载自blog.csdn.net/qq_26999509/article/details/78463459