xiandie/manager/audio_manager/vibe_sfx.gd
2025-07-03 17:51:21 +08:00

99 lines
2.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
class_name VibeSfx
extends Node
@export_tool_button("播放") var _play = _debug_play.bind(true)
@export_tool_button("停止") var _stop = _debug_play.bind(false)
## VibeSfx.gd
## 场景中的环境音效控制器节点(“遥控器”)。
## 你可以将此节点放置在任何场景中,用于配置和触发不同的 VibeGroup。
## 它通过调用全局的 VibeManager 来实现功能。
var autoplay_group: StringName
func _ready():
# 仅在游戏运行时执行
if Engine.is_editor_hint():
return
if autoplay_group:
switch_to(autoplay_group)
# ground 退出时process mode 切换为 alwaysease out
SceneManager.ground_transition_pre_paused.connect(_on_ground_transition_pre_paused)
func _on_ground_transition_pre_paused():
if current_group:
print("[GroundTransition] VibeSfx %s ease killing group %s" % [name, current_group])
AudioManager.stop_group(current_group)
# var debug_audio_manager: AudioManager
func _debug_play(play: bool):
# if not debug_audio_manager:
# debug_audio_manager = AudioManager.new()
# add_child(debug_audio_manager)
# if play:
# debug_audio_manager.play_group(autoplay_group)
# else:
# debug_audio_manager.stop_group(autoplay_group)
if play:
AudioManager.play_group(autoplay_group)
else:
AudioManager.stop_group(autoplay_group)
var current_group: StringName
## 公共方法:切换到指定的 VibeGroup。
## 可以在其他脚本(如过场动画控制器、区域触发器)中调用此方法。
## example: $VibeSfx.switch_to("event_1_vibe")
func switch_to(group_name: StringName):
if current_group:
AudioManager.stop_group(current_group)
current_group = group_name
AudioManager.play_group(group_name)
func stop():
if current_group:
AudioManager.stop_group(current_group)
func _exit_tree() -> void:
stop()
func _get(property: StringName) -> Variant:
if property == "autoplay_group":
return autoplay_group
return null
func _set(property: StringName, value: Variant) -> bool:
if property == "autoplay_group":
if current_group:
AudioManager.stop_group(current_group)
current_group = ""
autoplay_group = value
return true
return false
func _get_property_list() -> Array[Dictionary]:
var hint_str = ""
if is_node_ready():
hint_str = ",".join(AudioManager.VIBE_GROUPS)
return [
{
"name": "autoplay_group",
"type": TYPE_STRING,
"hint": PROPERTY_HINT_ENUM_SUGGESTION,
"hint_string": hint_str
}
]