export default class UserDataMgr { private static instance: UserDataMgr = null; public static getInstance() { if (!UserDataMgr.instance) { UserDataMgr.instance = new UserDataMgr(); UserDataMgr.instance.loadLocalData(); } return UserDataMgr.instance; } /** * 当前解锁等级 */ levelId: number = 0; /** * 游戏局数 */ gameCount: number = 0; /** * 最高分数 */ maxScore: number = 0; /** * 消耗的卡路里数 */ calorie: number = 0; // 等级数据 levelScoreData: { [key: number]: number } = {}; isFirst: boolean = true; public loadLocalData() { //TODO app接口 let data = Laya.LocalStorage.getJSON("gameData"); this.setData(data); } public syncSaveData() { //TODO app存储接口 Laya.LocalStorage.setJSON("gameData", this); } private setData(data: any) { if (data) { this.levelId = data.levelId; this.maxScore = data.maxScore; this.gameCount = data.gameCount; this.calorie = data.calorie; this.levelScoreData = data.levelScoreData || {}; this.isFirst = data.isFirst; } else { this.syncSaveData(); } } }