Starter.ts
2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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) {}
}