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”);
主要通过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保存数据方式——PlayerPrefs
- KenDoTreeview刷新后展开的节点和选中的节点不变(KenDoTreeview中的数据通过KenDoGrid来进行保存、删除)
- 通过CommandBuilder对DataSet数据进行添加、修改、删除
- 通过直接控制DNS进程进行数据传输
- 通过 IDictionary对Silverlight DataGrid 进行动态数据绑定
- 使用OleVariant进行二进制数据保存(delphi6)
- [原创]将TDC进行到底:将数据保存到Excel里
- 用客户端脚本提示用户在离开编辑页面之前进行数据保存
- 用javascript读取xml,并进行修改xml数据,解决保存没有权限问题
- 对于一系列数据通过单击进行排序(每次只能单击一次)
- JavaScript通过Flash保存本地数据
- 通过WM_COPY进行跨进程数据传递
- 使用热备份进行分时恢复----怎样通过归档逐步恢复以缩短数据迁移时间
- flex3通过fluorinefx跟asp.net进行数据交互
- 如何对dataset中进行修改并把修改后的数据保存到数据库中?
- PB中通过单击数据窗口中的列来对数据进行排序
- compass 整合hibernate spring 的第二种方式 ( 通过 定时器进行数据同步)compass-2.2.0 lucene-2.9.2. hibernate-distribut spring 2.5.6 paoding
- 通过存储过程来进行数据绑定
- GridView通过按钮增加行记录(无数据源)可以叠加保存数据!
- 对于一系列数据通过单击进行排序(可以多次单击)