|
|
@@ -1,4 +1,4 @@
|
|
|
-import { _decorator, Component, Node, Vec3, find, instantiate, Prefab, UITransform, resources, sp, CircleCollider2D, Contact2DType, Collider2D, IPhysics2DContact } from 'cc';
|
|
|
+import { _decorator, Component, Node, Vec3, find, instantiate, Prefab, UITransform, resources, sp, CircleCollider2D, Contact2DType, Collider2D, IPhysics2DContact, Animation } from 'cc';
|
|
|
import { BulletTrajectory } from './BulletTrajectory';
|
|
|
import { HitEffectConfig } from '../../Core/ConfigManager';
|
|
|
import { PersistentSkillManager } from '../../FourUI/SkillSystem/PersistentSkillManager';
|
|
|
@@ -8,6 +8,7 @@ import { GroundBurnAreaManager } from './GroundBurnAreaManager';
|
|
|
import { WeaponBullet } from '../WeaponBullet';
|
|
|
import EventBus, { GameEvents } from '../../Core/EventBus';
|
|
|
import { Audio } from '../../AudioManager/AudioManager';
|
|
|
+import { BundleLoader } from '../../Core/BundleLoader';
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
/**
|
|
|
@@ -699,12 +700,25 @@ export class BulletHitEffect extends Component {
|
|
|
private spawnEffect(path: string, worldPos: Vec3, loop = false, parent?: Node, onCreated?: (effectNode: Node) => void): void {
|
|
|
if (!path) return;
|
|
|
|
|
|
- const spawnWithData = (skData: sp.SkeletonData) => {
|
|
|
+ // 使用BundleLoader加载Animation Bundle中的特效资源
|
|
|
+ // 转换路径格式,去除"Animation/"前缀
|
|
|
+ const bundlePath = path.replace(/^Animation\//, '');
|
|
|
+ const bundleLoader = BundleLoader.getInstance();
|
|
|
+
|
|
|
+ // 使用loadSkeletonData加载骨骼动画资源,就像敌人动画那样
|
|
|
+ BundleLoader.loadSkeletonData(bundlePath).then((skData) => {
|
|
|
+ if (!skData) {
|
|
|
+ console.warn('加载特效失败: 资源为空', path);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建特效节点
|
|
|
const effectNode = new Node('Effect');
|
|
|
const skeletonComp: sp.Skeleton = effectNode.addComponent(sp.Skeleton);
|
|
|
skeletonComp.skeletonData = skData;
|
|
|
skeletonComp.setAnimation(0, 'animation', loop);
|
|
|
|
|
|
+ // 设置父节点和位置
|
|
|
const targetParent = parent || find('Canvas/GameLevelUI/enemyContainer') || find('Canvas');
|
|
|
if (targetParent) {
|
|
|
targetParent.addChild(effectNode);
|
|
|
@@ -719,9 +733,12 @@ export class BulletHitEffect extends Component {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 非循环动画播放完毕后销毁节点
|
|
|
if (!loop) {
|
|
|
skeletonComp.setCompleteListener(() => {
|
|
|
- effectNode.destroy();
|
|
|
+ if (effectNode && effectNode.isValid) {
|
|
|
+ effectNode.destroy();
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -729,15 +746,8 @@ export class BulletHitEffect extends Component {
|
|
|
if (onCreated) {
|
|
|
onCreated(effectNode);
|
|
|
}
|
|
|
- };
|
|
|
-
|
|
|
- // 先尝试直接加载给定路径
|
|
|
- resources.load(path, sp.SkeletonData, (err, skData: sp.SkeletonData) => {
|
|
|
- if (err) {
|
|
|
- console.warn('加载特效失败:', path, err);
|
|
|
- return;
|
|
|
- }
|
|
|
- spawnWithData(skData);
|
|
|
+ }).catch((err) => {
|
|
|
+ console.warn('加载特效失败:', path, err);
|
|
|
});
|
|
|
}
|
|
|
|