您的位置:首页 > 移动开发 > Unity3D

Unity中通过PlayerPrefs进行数据保存

2016-08-23 20:50 459 查看
在Unity中存储数据也是通过键值对的方式来进行。

主要通过PlayerPrefs来完成。

通过PlayerPrefs可以用来保存和访问玩家的偏好设置。

在Mac OS X中,PlayerPrefs的数据保存在~/Library/Preferences文件夹中,以unity.[company name].[product name].plist来命名。该文件在调试和正常运行中数据共享。

在Windows中,PlayerPrefs的数据保存在注册表HKCU\Software[company name][product name] key中。

在Linux中,PlayerPrefs的数据保存在

~/.config/unity3d/[CompanyName]/[ProductName]中。

类方法

◆ static function DeleteAll(): void

描述:从设置文件中移除所有键和值,谨慎的使用它们。

◆ static function DeleteKey(key: string): void

描述:从设置文件中移除key和它对应的值。

◆ static function GetFloat(key: string, defaultValue: float=OF): float

描述:如果存在,返回设置文件中key对应的值.如果不存在,它将返回defaultValue。

print(PlayerPrefs.GetFlat(“Player score”));

◆ static function GetInt(key: string, defaultValue: int): int

描述:返回设置文件中key对应的值,如果存在.如果不存在,它将返回defaultValue。

print(PlayerPrefs.GetInt(“Player score”));

◆ static function GetString(key: string, defaultValue: string=**): string

描述:返回设置文件中key对应的值,如果存在.如果不存在,它将返回defaultValue.

print(PlayerPrefs.GetString(“Player Name”));

◆ static function HasKey(key: string): bool

描述:在设置文件如果存在key则返回真.

◆ static function SetFloat(key: string, value: float): void

描述:设置由key确定的值.

print(PlayerPrefs.SetFloat(“Player Score”, 10.0));

◆ static function SetInt(key: string, value: int): void

描述:设置由key确定的值.

PlayerPrefs.SetInt(“Player Score”, 10);

◆ static function SetString(key: string, value: string): void

描述:设置由key确定的值.

PlayerPrefs.Setstring(“Player Name”, “Foobar”);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity 数据 存储