import { _decorator, Camera, Component, JsonAsset, Material, Node, Sprite } from 'cc'; import { rootMgr } from './RootMgr'; import { AssetType, ResUtil } from '../util/ResUtil'; import { CfgMgr } from '../util/CfgMgr'; import { GameControl } from '../GameContorl/GameControl'; import { FMSType } from '../GameContorl/fms/FMSGameInit'; import { MySave } from '../../scripts/uitl/baseData/saveCompent/MySave'; import { GameCompent } from '../GameContorl/GameComponent'; import { aa } from '../../scripts/aa'; import { SaveComponent } from './GameConfing'; import { UI_Notify } from '../ui/ui_notify/UI_Notify'; import { Player } from '../data/player/Player'; const { ccclass, property } = _decorator; @ccclass('GameRoot') export class GameRoot extends Component { start() { this.initData() this.loadData() aa.uIMgr.showUI(UI_Notify) ResUtil.loadResToMap(AssetType.Json, (json: JsonAsset[]) => { let res = {} json.forEach((mat) => { res[mat.name] = mat.json CfgMgr.setCfgData(mat.name, mat.json) }) return res }, () => { rootMgr.game.FMS.Change(FMSType.home) }) rootMgr.game.evt.on("save", this.doSave, this) } doSave(force: boolean) { // 保存 this.isNeedSave = true if (force) { this.saveData() } } protected onDestroy(): void { rootMgr.game?.clear() rootMgr.gameCompent?.clear() rootMgr.rooView = null rootMgr.game = null rootMgr.dataControl = null rootMgr.gameCompent = null } rePlay() { this.scheduleOnce(() => { rootMgr.game.init() }, .1) } initData() { rootMgr.rooView = this rootMgr.game = new GameControl rootMgr.dataControl = new MySave rootMgr.gameCompent = new GameCompent } loadData() { let data = aa.data.get(SaveComponent.getGameData()) rootMgr.dataControl.init(data) rootMgr.dataControl.getCompent(Player).init() } async loadInfo(): Promise { return new Promise( async (resolve) => { // aa.uIMgr.showUI(UIWaiting_Impl); // let k = await chsdk.getUserInfo(); // if (k) { // resolve(true); // } else { // resolve(false); // Notify("需要授权"); // } // aa.uIMgr.closeUI(UIWaiting_Impl); } ) } isNeedSave = true saveData() { let data = rootMgr.dataControl.serialize() aa.data.set(SaveComponent.getGameData(), data) this.isNeedSave = false } protected update(dt: number): void { if (!this.isNeedSave) return this.saveData() } }