数据存储(一)PlayerPrefs存储数据
2018-08-17 本文已影响7人
无赖宵小
(一)PlayerPrefs
特点:存储方式简单,但不实用,可以用于少量数据的存储。
适用设备:Mac OSX, Linux, Windows,Web Players;
存储机制:Key-Value (类似于字典的键值对,通过键值索引到相应数据);
可存储变量类型:int, float, string。
(二)常用方法:
SetFloat:存储float 类型的数据
GetFloat:获取float 类型的数据
SetInt:存储Int类型的数据
GetInt:获取Int 类型的数据
SetString:存储string 类型的数据
GetString:获取string 类型的数据
DeleteAll:删除所有PlayerPrefs数据
HasKey:判断是否存在该Key值的数据
(三)简单代码:
void ExamplePlayerPrefs()
{
PlayerPrefs.SetFloat("PlayerScore", 10f);
Debug.Log(PlayerPrefs.GetFloat("PlayerScore"));
}