From 7a56644b4545e344d424175876d3ecd279d8b598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Fri, 29 Aug 2025 11:37:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(BulletBase):=20=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=94=80=E6=AF=81=E5=8A=A8=E7=94=BB=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为子弹基类添加 autoDestroyAnimation 导出变量,当设置为 true 时会在销毁时播放销毁动画 --- components/Abstracts/BulletBase.tscn | 8 +++++++- scripts/Statemachine/BulletBase.gd | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/Abstracts/BulletBase.tscn b/components/Abstracts/BulletBase.tscn index 39d57e1..872dcff 100644 --- a/components/Abstracts/BulletBase.tscn +++ b/components/Abstracts/BulletBase.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://crtdkysmnkith"] +[gd_scene load_steps=8 format=3 uid="uid://crtdkysmnkith"] [ext_resource type="Script" path="res://scripts/Statemachine/BulletBase.gd" id="1_pklpq"] @@ -24,8 +24,14 @@ tracks/0/keys = { [sub_resource type="Animation" id="Animation_kmogx"] resource_name = "spawn" +[sub_resource type="Animation" id="Animation_oinqg"] +resource_name = "destroy" +length = 0.5 +step = 0.1 + [sub_resource type="AnimationLibrary" id="AnimationLibrary_dxweq"] _data = { +"destroy": SubResource("Animation_oinqg"), "loop": SubResource("Animation_ynxlt"), "spawn": SubResource("Animation_kmogx") } diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index c682ee8..bfdeaf4 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -11,6 +11,7 @@ class_name BulletBase @export var needEnergy: float = 0.0 # 发射时需要消耗的能量 @export var autoSpawnAnimation: bool = false @export var autoLoopAnimation: bool = false +@export var autoDestroyAnimation: bool = false @export var freeAfterSpawn: bool = false @export var knockback: float = 0 # 击退力,物理引擎单位 @export var recoil: float = 0 # 后坐力,物理引擎单位 @@ -74,6 +75,9 @@ func dotLoop(): func ai(): pass func destroy(): + if autoDestroyAnimation: + animator.play("destroy") + await animator.animation_finished queue_free() func spawn(): pass