diff --git a/assets/script/tetriCard/tetriWeaponCarrier.ts b/assets/script/tetriCard/tetriWeaponCarrier.ts index 9cc3c7e9..2253570d 100644 --- a/assets/script/tetriCard/tetriWeaponCarrier.ts +++ b/assets/script/tetriCard/tetriWeaponCarrier.ts @@ -66,6 +66,10 @@ export class tetriWeaponCarrier extends Component { initRoleFacingFix: number = 0; private roleNode: Node | null = null; private roleBaseAbsScaleX: number = 1; + /** 寮傛鍒涘缓瑙掕壊杩涜涓?*/ + private _roleCreating = false; + /** 姝﹀櫒寮傛鍔犺浇搴忓彿锛屼涪寮冭繃鏈熷洖璋?*/ + private _weaponLoadSeq = 0; _isBattleScene = false //鏄惁鏄垬鏂楀満鏅浉鏈? _isCanShoot = true //鏄惁鍙互灏勫嚮 @@ -124,6 +128,8 @@ export class tetriWeaponCarrier extends Component { const role = this.roleNode; this.weaponNode = null; this.roleNode = null; + this._roleCreating = false; + this._weaponLoadSeq++; // 姝﹀櫒鎸傚湪銆岃鑹?姝﹀櫒銆嶄笅锛屽厛鍥炴敹姝﹀櫒鍐嶅洖鏀惰鑹诧紝閬垮厤瀛愰殢鐖朵竴璧疯繘鍗婇攢姣佹€? if (this.timeoutIndex) clearTimeout(this.timeoutIndex as unknown as number); GEvent.Ins.off(GEvent.ChangeCubeWeaponConfig, this.ChangeCubeWeapon, this) @@ -189,8 +195,8 @@ export class tetriWeaponCarrier extends Component { this.roleNode.setScale(conf.scalex, conf.scaley); const anim = this.roleNode.getChildByName('anim')?.getComponent(sp.Skeleton); if (anim) { - anim.setAnimation(0, '寰呮満', true); anim.setSkin(conf.animSkin); + anim.setAnimation(0, '寰呮満', true); } else { console.warn('[tetriWeaponCarrier] createRoleNode: 瑙掕壊 prefab 缂哄皯 anim 瀛愯妭鐐?, this._config.cubename); } @@ -207,7 +213,7 @@ export class tetriWeaponCarrier extends Component { this.roleBaseAbsScaleX = abs > 1e-6 ? abs : 1; } createRoleNode() { - if (this.roleNode?.isValid) return + if (this.roleNode?.isValid || this._roleCreating) return // 鍏堟寕瑙掕壊鑺傜偣锛屽啀 setView -> addWeapon锛堜緷璧栧瓙璺緞 瑙掕壊/anim銆佽鑹?姝﹀櫒锛? if (!this._config) { console.error('[tetriWeaponCarrier] createRoleNode: _config 涓虹┖锛岃淇濊瘉 setConfig 鍦?start 涔嬪墠宸茶皟鐢?); @@ -229,8 +235,14 @@ export class tetriWeaponCarrier extends Component { let roleNode: Node | null = existingRole?.isValid ? existingRole : null; if (!roleNode) { + this._roleCreating = true; void gg.res.getNodeAsync('瑙掕壊/', '瑙掕壊', GBundle.tetriCards).then((loaded) => { + this._roleCreating = false; if (!loaded?.isValid || !this.node?.isValid) return; + if (this.roleNode?.isValid) { + this.safePutPoolNode(loaded); + return; + } this._setupRoleNode(loaded); }); return; @@ -238,23 +250,30 @@ export class tetriWeaponCarrier extends Component { this._setupRoleNode(roleNode); } + private _dedupeRoleChildren(keep: Node): void { + for (let i = this.node.children.length - 1; i >= 0; i--) { + const c = this.node.children[i]; + if (c.name === '瑙掕壊' && c !== keep && c?.isValid) c.destroy(); + } + } + private _setupRoleNode(roleNode: Node) { roleNode.setParent(this.node); this.roleNode = roleNode; roleNode.active = true; + this._dedupeRoleChildren(roleNode); const roleComp = roleNode.getComponent(role); roleComp?.setFollowTarget(this.findCarrierTetriNode()?.node ?? this.node); const conf = this.roleConfig.find(item => item.name == this._config.cubename); - // console.log('conf',conf); if (conf) { roleNode.setPosition(conf.mainPosi.x, conf.mainPosi.y); roleNode.setScale(conf.scalex, conf.scaley); const anim = roleNode.getChildByName('anim')?.getComponent(sp.Skeleton); if (anim) { - anim.setAnimation(0, '寰呮満', true); anim.setSkin(conf.animSkin); + anim.setAnimation(0, '寰呮満', true); } else { console.warn('[tetriWeaponCarrier] createRoleNode: 瑙掕壊 prefab 缂哄皯 anim 瀛愯妭鐐?, this._config.cubename); } @@ -419,8 +438,14 @@ export class tetriWeaponCarrier extends Component { console.error('[tetriWeaponCarrier] addWeapon: 鏈壘鍒?瑙掕壊/anim 鎴?瑙掕壊/姝﹀櫒', this._config?.cubename); return; } + const loadSeq = ++this._weaponLoadSeq; void gg.res.getNodeAsync('prefab/', weaponani, GBundle.tetriWeapon).then((weaponNode) => { + if (loadSeq !== this._weaponLoadSeq) { + this.safePutPoolNode(weaponNode); + return; + } if (!weaponNode?.isValid || !wuqiNode?.isValid) return; + this.safePutPoolNode(this.weaponNode); this.setLayerMask(weaponNode, wuqiNode.layer); this.weaponNode = weaponNode; weaponNode.setParent(wuqiNode);