Unity3d 中 PlayerPrefs 保存数据的总结


1.PlayerPrefs 可以保存玩家数据,但限于保存小型的数据(适合与本地玩家和场景间传值)


 Application.persisteneDataPath:永久数据保存区

  
PlayerPrefs 保存的位置: 

Mac:存储在~/Library/PlayerPrefs 文件夹,名为 unity.[company name].[product name].plist 

Windows:存储在注册表的 HKCU\Software\[company name]\[product name]键下

 Linux:存储在~/.config/unity3d/[CompanyName]/[ProductName] 

Windows Store Apps:存储 在%userprofile%\AppData\Local\Packages\[ProductPackageId]>\LocalState\playerpr efs.dat 

Windows Phone 8:存储在自身工程文件夹下, See Also: Windows.Directory.localFolder 

Web:存储在 Mac OS X 的二进制文件~/Library/Preferences/Unity/WebPlayerPrefs 中和 Windows 的%APPDATA%\Unity\WebPlayerPrefs 中,一个偏好设置文件对应一个 web 播放 器 URL 并且文件大小被限制为 1MB。如果超出这个限制,SetInt、SetFloat 和 SetString 将不会存储值并抛出一个 PlayerPrefsException。 这里的[company name].[product name]指的是Windows 下注册表的位置是:(中文会出现乱码) 
  PlayerPrefs 类可以保存3种基本的数据类型,他们是浮点型,整型和字符串型。 SetFloat():保存浮点类型。 SetInt():保存整型。 SetString():保存字符串。 GetFloat():获取浮点类型。 GetInt():获取整型。 GetString():获取字符串。 PlayerPrefs 类提供了两种删除数据的方法。 DeleteAll():删除所有键和对应的值 DeleteKey():删除指定的键和对应的值 HasKey():如果存在键就返回 True。 Save():保存所有修改的玩家设置参数,默认 Unity 在程序退出时保存参数



猜你喜欢

转载自blog.csdn.net/qq_34678199/article/details/51860398