mirror of
https://github.com/Rundll86/Dog-Lynx-And-HCN.git
synced 2026-05-27 22:41:56 +08:00
30527a18a8
- 新增GameControl节点用于统一处理游戏重启和退出 - 添加GameBusManager管理游戏重启时的资源清理 - 修改Pause和GameOver面板使用新的GameControl - 为EffectController和ItemDropped添加分组管理 - 统一使用WorldManager管理游戏时间
64 lines
1.7 KiB
GDScript
64 lines
1.7 KiB
GDScript
extends Node2D
|
|
class_name EffectController
|
|
|
|
@export var oneShot: bool = true
|
|
@export var spawnSound: String = ""
|
|
@export var spawnAnimation: String = ""
|
|
@export var spawnTexture: String = ""
|
|
@export var lockTexture: bool = false
|
|
|
|
@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 _physics_process(_delta):
|
|
if lockTexture:
|
|
texture.global_rotation = 0
|
|
func shot():
|
|
beforeShot()
|
|
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 spawnTexture:
|
|
if texture.is_playing():
|
|
await texture.animation_finished
|
|
texture.hide()
|
|
if childParticle.emitting:
|
|
await childParticle.finished
|
|
childParticle.queue_free()
|
|
if spawnSound:
|
|
if sound.playing:
|
|
await sound.finished
|
|
if spawnAnimation:
|
|
if animator.is_playing():
|
|
await animator.animation_finished
|
|
queue_free()
|
|
|
|
func register():
|
|
pass
|
|
func beforeShot():
|
|
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)
|
|
cloned.add_to_group("effects")
|
|
return cloned
|