PlayerPrefs - 将数据保存到设备
1 分
提供将玩家保存到他们连接的设备的能力。 如果您删除应用程序或更改设备,数据将不会被保留。
它支持与Unity中的PlayerPrefs相同的使用方式,存储容量限制为10KB。
▼ 使用保存和加载功能检查播放次数的示例代码
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { PlayerPrefs } from 'UnityEngine';
export default class ClientSaveLoad extends ZepetoScriptBehaviour {
private playCntKey: string = 'KeyName';
Start() {
if (PlayerPrefs.HasKey(this.playCntKey)) {
PlayerPrefs.SetInt(this.playCntKey, PlayerPrefs.GetInt(this.playCntKey) + 1);
console.log(`PlayCnt : ${ PlayerPrefs.GetInt(this.playCntKey) }`);
} else {
PlayerPrefs.SetInt(this.playCntKey, 1);
console.log('PlayCnt : 1');
}
}
}📘 查看Unity PlayerPrefs信息 https://docs.unity3d.com/ScriptReference/PlayerPrefs.html