PlayerPrefs - デバイスにデータを保存
1 分
接続しているデバイスにプレイヤーを保存する機能を提供します。 クライアントZEPETOスクリプトから呼び出すことができ、アプリを削除したりデバイスを変更した場合、データは保持されません。
UnityのPlayerPrefsと同様に使用をサポートしており、ストレージ容量は10KBに制限されています。
▼ Save & Load機能を使用してプレイ回数を確認するための例コード
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