gameend_debug_patch.ts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. * GameEnd调试补丁
  3. * 将以下代码添加到GameEnd.ts中对应的方法里,用于诊断墙体血量为0时动画不显示的问题
  4. */
  5. // ===== 在GameEnd.ts的start()方法中添加 =====
  6. console.log('[GameEnd] 🔧 调试信息 - 组件初始化:');
  7. console.log(' - animationDuration:', this.animationDuration);
  8. console.log(' - 节点名称:', this.node?.name);
  9. console.log(' - 节点激活状态:', this.node?.active);
  10. console.log(' - 节点层级索引:', this.node?.getSiblingIndex());
  11. if (this.node?.parent) {
  12. console.log(' - 父节点子节点数量:', this.node.parent.children.length);
  13. console.log(' - Canvas子节点列表:');
  14. this.node.parent.children.forEach((child, index) => {
  15. console.log(` ${index}: ${child.name} (active: ${child.active}, siblingIndex: ${child.getSiblingIndex()})`);
  16. });
  17. }
  18. // ===== 在GameEnd.ts的setupEventListeners()方法中添加 =====
  19. console.log('[GameEnd] 🎯 调试信息 - 事件监听器注册:');
  20. console.log(' - EventBus实例:', eventBus);
  21. console.log(' - 当前组件实例:', this);
  22. console.log(' - GAME_DEFEAT事件监听器已注册');
  23. // ===== 在GameEnd.ts的onGameDefeat()方法开始处添加 =====
  24. console.log('\n🚨 [GameEnd] GAME_DEFEAT事件触发 - 详细调试信息:');
  25. console.log(' - 触发时间:', new Date().toLocaleTimeString());
  26. console.log(' - hasProcessedGameEnd:', this.hasProcessedGameEnd);
  27. console.log(' - 节点激活状态:', this.node?.active);
  28. console.log(' - 节点层级索引:', this.node?.getSiblingIndex());
  29. console.log(' - animationDuration:', this.animationDuration);
  30. // 检查UIOpacity组件
  31. const uiOpacity = this.node?.getComponent(UIOpacity);
  32. console.log(' - UIOpacity组件存在:', !!uiOpacity);
  33. if (uiOpacity) {
  34. console.log(' - 当前透明度:', uiOpacity.opacity);
  35. }
  36. // 检查节点缩放
  37. if (this.node) {
  38. console.log(' - 当前缩放:', this.node.scale);
  39. console.log(' - 当前位置:', this.node.position);
  40. }
  41. // 检查是否被其他UI遮挡
  42. if (this.node?.parent) {
  43. const higherLevelPanels = this.node.parent.children.filter(child =>
  44. child.getSiblingIndex() > this.node.getSiblingIndex() && child.active && child !== this.node
  45. );
  46. if (higherLevelPanels.length > 0) {
  47. console.log(' - ⚠️ 发现更高层级的激活面板:');
  48. higherLevelPanels.forEach(panel => {
  49. console.log(` - ${panel.name} (siblingIndex: ${panel.getSiblingIndex()})`);
  50. });
  51. } else {
  52. console.log(' - ✅ 没有更高层级的面板遮挡');
  53. }
  54. }
  55. // ===== 在GameEnd.ts的showEndPanelWithAnimation()方法开始处添加 =====
  56. console.log('[GameEnd] 🎬 showEndPanelWithAnimation调试:');
  57. console.log(' - 方法被调用时间:', new Date().toLocaleTimeString());
  58. console.log(' - 节点激活状态:', this.node?.active);
  59. console.log(' - animationDuration:', this.animationDuration);
  60. // ===== 在GameEnd.ts的playShowAnimation()方法开始处添加 =====
  61. console.log('[GameEnd] 🎭 playShowAnimation调试:');
  62. console.log(' - 动画开始时间:', new Date().toLocaleTimeString());
  63. console.log(' - 节点存在:', !!this.node);
  64. if (this.node) {
  65. console.log(' - 动画前节点状态:');
  66. console.log(' - 激活:', this.node.active);
  67. console.log(' - 缩放:', this.node.scale);
  68. console.log(' - 位置:', this.node.position);
  69. const uiOpacity = this.node.getComponent(UIOpacity);
  70. console.log(' - UIOpacity存在:', !!uiOpacity);
  71. if (uiOpacity) {
  72. console.log(' - 透明度:', uiOpacity.opacity);
  73. }
  74. }
  75. // ===== 在tween动画的.call()回调中添加 =====
  76. // 替换原有的缩放动画为:
  77. tween(this.node)
  78. .to(this.animationDuration, {
  79. scale: new Vec3(1, 1, 1)
  80. }, {
  81. easing: 'backOut'
  82. })
  83. .call(() => {
  84. console.log('[GameEnd] ✨ 缩放动画完成 - 详细状态:');
  85. console.log(' - 完成时间:', new Date().toLocaleTimeString());
  86. console.log(' - 节点激活:', this.node?.active);
  87. console.log(' - 最终缩放:', this.node?.scale);
  88. console.log(' - 最终位置:', this.node?.position);
  89. const uiOpacity = this.node?.getComponent(UIOpacity);
  90. if (uiOpacity) {
  91. console.log(' - 最终透明度:', uiOpacity.opacity);
  92. }
  93. // 检查节点是否真的可见
  94. if (this.node) {
  95. const isVisible = this.node.active &&
  96. this.node.scale.x > 0.1 &&
  97. this.node.scale.y > 0.1 &&
  98. (uiOpacity?.opacity || 0) > 10;
  99. console.log(' - 计算可见性:', isVisible);
  100. }
  101. })
  102. .start();
  103. // 替换原有的透明度动画为:
  104. tween(uiOpacity)
  105. .to(this.animationDuration, {
  106. opacity: 255
  107. })
  108. .call(() => {
  109. console.log('[GameEnd] ✨ 透明度动画完成:');
  110. console.log(' - 完成时间:', new Date().toLocaleTimeString());
  111. console.log(' - 最终透明度:', uiOpacity?.opacity);
  112. })
  113. .start();
  114. // ===== 在Wall.ts的onWallDestroyed()方法中添加 =====
  115. console.log('\n🧱 [Wall] 墙体被摧毁调试信息:');
  116. console.log(' - 摧毁时间:', new Date().toLocaleTimeString());
  117. console.log(' - 当前血量:', this.currentHealth);
  118. console.log(' - EventBus实例:', eventBus);
  119. console.log(' - 即将触发GAME_DEFEAT事件');
  120. // 在触发事件后添加:
  121. eventBus.emit(GameEvents.GAME_DEFEAT);
  122. console.log(' - ✅ GAME_DEFEAT事件已触发');
  123. // ===== 强制显示测试代码(添加到onGameDefeat方法中,用于快速验证) =====
  124. // 在onGameDefeat方法的最后添加这段强制显示代码:
  125. console.log('[GameEnd] 🧪 强制显示测试:');
  126. if (this.node) {
  127. // 强制设置节点状态
  128. this.node.active = true;
  129. this.node.setScale(1, 1, 1);
  130. this.node.setPosition(0, 0, 0);
  131. const uiOpacity = this.node.getComponent(UIOpacity);
  132. if (uiOpacity) {
  133. uiOpacity.opacity = 255;
  134. }
  135. console.log(' - 强制显示完成,节点状态:');
  136. console.log(' - 激活:', this.node.active);
  137. console.log(' - 缩放:', this.node.scale);
  138. console.log(' - 位置:', this.node.position);
  139. console.log(' - 透明度:', uiOpacity?.opacity);
  140. // 延迟检查是否真的显示了
  141. setTimeout(() => {
  142. console.log('[GameEnd] 🔍 强制显示后延迟检查:');
  143. console.log(' - 节点仍然激活:', this.node?.active);
  144. console.log(' - 缩放保持:', this.node?.scale);
  145. console.log(' - 透明度保持:', this.node?.getComponent(UIOpacity)?.opacity);
  146. }, 100);
  147. }
  148. // ===== 使用说明 =====
  149. /*
  150. 使用步骤:
  151. 1. 将上述对应的代码片段添加到GameEnd.ts和Wall.ts的相应方法中
  152. 2. 在Cocos Creator中重新编译项目
  153. 3. 运行游戏并让墙体血量归零
  154. 4. 查看控制台输出,重点关注:
  155. - GAME_DEFEAT事件是否被触发
  156. - GameEnd组件是否接收到事件
  157. - showEndPanelWithAnimation是否被调用
  158. - 动画是否正确执行
  159. - 强制显示测试是否有效
  160. 如果强制显示有效,说明问题在动画系统;
  161. 如果强制显示无效,说明问题在节点配置或UI层级。
  162. 常见问题排查:
  163. 1. animationDuration为0 → 动画不执行
  164. 2. 节点被其他UI遮挡 → 检查siblingIndex
  165. 3. UIOpacity组件缺失 → 透明度控制失效
  166. 4. EventBus实例不一致 → 事件监听失效
  167. 5. 节点在运行时被其他脚本修改 → 检查其他组件
  168. */