1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-05-28 06:51:54 +08:00
Files
Dog-Lynx-And-HCN/scripts/Statemachine/EffectController.gd
T
fallingshrimp aa3f34ca74 feat(武器): 增强格挡武器并添加新特效
增加格挡武器的攻击力从20提升至35
添加冲刺速度随气力增加的机制
为格挡和攻击添加新的视觉特效和音效
调整格挡子弹的碰撞检测形状
优化特效控制器逻辑确保正确释放资源
2026-03-21 18:55:32 +08:00

56 lines
1.5 KiB
GDScript

extends Node2D
class_name EffectController
@export var oneShot: bool = true
@export var spawnSound: String = ""
@export var spawnAnimation: String = ""
@export var spawnTexture: String = ""
@onready var particles: GPUParticles2D = $"%particles"
@onready var sounds: Node2D = $"%sounds"
@onready var animator: AnimationPlayer = $"%animator"
@onready var texture: AnimatedSprite2D = $"%texture"
func _ready():
register()
particles.emitting = false
particles.one_shot = oneShot
func shot():
var childParticle = particles.duplicate() as GPUParticles2D
childParticle.emitting = true
add_child(childParticle)
var sound = sounds.get_node_or_null(spawnSound)
if sound and sound.stream:
sound.play()
if spawnAnimation:
animator.play(spawnAnimation)
if spawnTexture:
texture.play(spawnTexture)
if oneShot:
if childParticle.emitting:
await childParticle.finished
childParticle.queue_free()
if spawnTexture:
if texture.is_playing():
await texture.animation_finished
texture.hide()
if spawnSound:
if sound.playing:
await sound.finished
if spawnAnimation:
if animator.is_playing():
await animator.animation_finished
queue_free()
func register():
pass
static func create(scene: PackedScene, spawnPosition: Vector2, parent: Node = null) -> EffectController:
var cloned = scene.instantiate() as EffectController
cloned.global_position = spawnPosition
if parent:
parent.add_child(cloned)
else:
WorldManager.rootNode.add_child(cloned)
return cloned