- Cocos Creator里绑定properties
@property(cc.Prefab)
XXUIPrefab: cc.Prefab = null;
import { Constants, GameState } from "./data/DWJY_Constants";
const { ccclass, property } = cc._decorator;
@ccclass
export default class XXUI extends cc.Component {
@property(cc.Node)
closeBtn: cc.Node = null;
public init() {
this.node.active = true;
Constants.gameState = GameState.PAUSE;
}
private function() {
...
}
private close() {
this.node.active = false;
Constants.gameState = GameState.PLAYING;
}
}
- 设置一个打开它的函数,如果它已经存在则直接
init
,如果它不存在或已经被销毁,则instantiate
- 一般这个函数出现在gameManager的绑定脚本里
private showXXUI() {
let name = 'XXUI';
let node = this.UI.getChildByName(name);
if (!node || !cc.isValid(node)) {
node = cc.instantiate(this.XXUIPrefab);
node.parent = this.UI;
node.name = name;
}
node.getComponent(XXUI).init();
}