PlayerPrefs - การบันทึกข้อมูลลงบนอุปกรณ์
1 นาที
ให้ความสามารถในการบันทึกผู้เล่นลงในอุปกรณ์ที่พวกเขากำลังเชื่อมต่ออยู่ ข้อมูลจะไม่ถูกเก็บรักษาหากคุณลบแอปหรือเปลี่ยนอุปกรณ์.
รองรับการใช้งานในลักษณะเดียวกับ PlayerPrefs ใน Unity และความจุในการจัดเก็บจำกัดอยู่ที่ 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');
}
}
}📘 ดูข้อมูล PlayerPrefs ของ Unity https://docs.unity3d.com/ScriptReference/PlayerPrefs.html