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