可以用,但是得解决一下循环引用问题。以下代码摘取自项目“HappyBall2(修复bug9.25)”
- 各种 Panel ->
PanelRoot
-> ResSvc
-> GameRoot
-> MainMgr
,最关键的在于 MainMgr
里面依赖了各种 Panel(通过 @property({type: XXPanel})
);
一种解决办法:
取消 GameRoot
对 MainMgr
的依赖。将 GameRoot.ts
中的
let mainMgr: MainMgr = this.node.getComponent(MainMgr);
改为
// 通过字符串而非类本身来获取 MainMgr 组件
// "MainMgr" 是 类 MainMgr 的 cc 名称,因为有:
// ```ts
// @ccclass("MainMgr") export class MainMgr
// ```
let mainMgr: MainMgr = this.node.getComponent('MainMgr') as MainMgr;
-
LoadPanel
-> PanelRoot
-> ResSvc
-> GameRoot
,GameRoot
本身依赖了 LoadPanel
(通过 @property(LoadPanel)
)
一种解决办法:
取消 GameRoot 对 LoadPanel 的依赖。将 GameRoot.ts
中的
@property(LoadPanel)
public loadPanel: LoadPanel = null;
改为
// 通过字符串而非类本身来标记属性类型为 LoadPanel;"loadPanel" 是 类 LoadPanel 的 cc 名称
@property('LoadPanel')
public loadPanel: LoadPanel = null;