// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import { SaveDataManager } from "../component/SaveDataManager"; import { SoundManager } from "../component/SoundManager"; import { tMgr, WindowName } from "../Global"; import { getGlobalNode } from "../kernel/battle/BattleConst"; import GlobalNode from "../kernel/GlobalNode"; import { TableMap } from "../kernel/table/TableDefine"; import { UIManager } from "../ui/UIManager"; const { ccclass, property } = cc._decorator; @ccclass export default class Starter extends cc.Component { // LIFE-CYCLE CALLBACKS: onLoad() { //#region 添加全局节点,UIRoot挂在全局节点下,位于Canvas上层,Canvas只显示场景 let gl = getGlobalNode(); // gl = new cc.Node(GLOBAL_NODE_NAME); cc.game.addPersistRootNode(gl); gl.addComponent(GlobalNode); let widget = gl.addComponent(cc.Widget); widget.isAlignLeft = true; widget.isAlignRight = true; widget.isAlignTop = true; widget.isAlignBottom = true; widget.left = 0; widget.right = 0; widget.top = 0; widget.bottom = 0; widget.updateAlignment(); let uiNode = this.node.getChildByName('UIRoot'); uiNode.removeFromParent(false); gl.addChild(uiNode); //#endregion UIManager.ins.init(uiNode); } start() { SaveDataManager.ins.init(); cc.resources.loadDir("data", cc.JsonAsset, this.onTableLoaded.bind(this)); } private onTableLoaded(error, data: cc.JsonAsset[]) { //#region 按钮添加音效 cc.Button.prototype['touchEndClone'] = cc.Button.prototype['_onTouchEnded']; cc.Button.prototype['_onTouchEnded'] = function (event) { if (this.interactable && this.enabledInHierarchy && this._pressed) { // log('播放音效'); SoundManager.ins.playEffect('Click'); } this.touchEndClone(event); } //#endregion for (let i = 0; i < data.length; ++i) { tMgr.setTable(data[i].name, data[i].json, TableMap[data[i].name]); } tMgr.parse(); if (SaveDataManager.ins.runtimeData.gender == -1) { // UIManager.ins.openWindow(WindowName.SELECT_GENDER); UIManager.ins.openScene('Opening'); } else { UIManager.ins.openScene('Main'); } } // update (dt) {} }