作者:mobiledu2502890053 | 来源:互联网 | 2023-05-17 11:53
这个PlayerPerfs类是Unity3D自带的小型化的数据存储的类,对于小数据完全适合usingUnityEngine;usingSystem.Colliections;publi
这个PlayerPerfs类是Unity3D自带的小型化的数据存储的类,对于小数据完全适合
using UnityEngine;
using System.Colliections;
public class PlayerPerfsExample:MonoBehaviour{
void Example()
{
//设置键值和值
PlayerPerfs.SetInt("keyInt",10);
PlayerPerfs.SetFloat("keyFloat",10.2f);
PlayerPerfs.SetString("keyString","lmzqm");
//获取键值如果不存在该键值就返回默认值0
PlayerPerfs.GetInt("keyInt",0);
PlayerPerfs.GetFloat("keyFloat",0);
PlayerPerfs.GetString("keyString","0");
PlayerPerfs.DeleteAll();//删除所有键值
PlayerPerfs.DeleteKey("keyInt");//删除某个键值
bool exist = PlayerPerfs.HasKey("keyInt");//判断是否存在键值
}
}