const { ccclass, property } = cc._decorator; @ccclass export default class RoleMergeScript extends cc.Component { @property(cc.Node) mergeNode: cc.Node = null; @property(cc.Node) roleNodeList: cc.Node[] = []; // onLoad () {} start() { for (const iterator of this.roleNodeList) { iterator.addComponent(RoleScript); iterator.attr({ scrRm: this }); } } mergeRoleNode(target) { let mActive = true; for (const iterator of this.roleNodeList) { mActive = iterator.active ? mActive : false; } if (mActive) { this.mergeNode.active = mActive; for (const iterator of this.roleNodeList) { iterator.active = false; } } } } class RoleScript extends cc.Component { protected onEnable(): void { (this.node).scrRm.mergeRoleNode(this.node); } }