fix(map): 修复卡片动画播放可能报错的问题
新增节点有效性和动画组件存在性校验,避免异步加载期间节点被销毁或组件被移除导致的运行时错误
This commit is contained in:
@@ -1038,9 +1038,18 @@ export class CardComp extends CCComp {
|
|||||||
if (token !== this.iconVisualToken) {
|
if (token !== this.iconVisualToken) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.clearAnimationClips(anim);
|
// 节点可能已在异步加载期间被销毁(如 cacheCardComps 重新实例化)
|
||||||
anim.addClip(clip);
|
if (!node || !node.isValid) {
|
||||||
anim.play("idle");
|
return;
|
||||||
|
}
|
||||||
|
// 重新获取 Animation 组件,防止原组件已被移除
|
||||||
|
const animComp = node.getComponent(Animation);
|
||||||
|
if (!animComp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.clearAnimationClips(animComp);
|
||||||
|
animComp.addClip(clip);
|
||||||
|
animComp.play("idle");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user