mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-28 15:01:53 +08:00
b5edbc5b13
feat(EntityBase): 添加获取生命值百分比的方法 refactor(BulletBase): 重命名scene变量为parentScene以提高可读性 fix(BlueCrystal): 修正弹道追踪旋转计算错误 style(EffectBase): 调整场景文件格式和属性顺序
37 lines
1011 B
GDScript
37 lines
1011 B
GDScript
extends Node2D
|
|
class_name EffectController
|
|
|
|
@export var oneShot: bool = true
|
|
@export var spawnSound: String = ""
|
|
@export var spawnAnimation: String = ""
|
|
|
|
@onready var particles: GPUParticles2D = $"%particles"
|
|
@onready var sounds: Node2D = $"%sounds"
|
|
@onready var animator: AnimationPlayer = $"%animator"
|
|
|
|
func _ready():
|
|
particles.emitting = false
|
|
particles.one_shot = oneShot
|
|
var sound = sounds.get_node_or_null(spawnSound)
|
|
if sound and sound.stream:
|
|
sound.play()
|
|
if spawnAnimation:
|
|
animator.play(spawnAnimation)
|
|
func shot():
|
|
var cloned = particles.duplicate() as GPUParticles2D
|
|
cloned.emitting = true
|
|
add_child(cloned)
|
|
if oneShot:
|
|
await cloned.finished
|
|
cloned.queue_free()
|
|
queue_free()
|
|
|
|
static func create(scene: PackedScene, spawnPosition: Vector2, parent: Node2D = 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
|