xiandie/manager/audio_manager/vibe_sfx.gd

91 lines
2.1 KiB
GDScript3
Raw Normal View History

2025-06-18 13:48:59 +00:00
@tool
class_name VibeSfx
extends Node
2025-06-25 17:53:16 +00:00
@export_tool_button("播放") var _play = _debug_play.bind(true)
@export_tool_button("停止") var _stop = _debug_play.bind(false)
2025-06-18 13:48:59 +00:00
## VibeSfx.gd
## 场景中的环境音效控制器节点(“遥控器”)。
## 你可以将此节点放置在任何场景中,用于配置和触发不同的 VibeGroup。
## 它通过调用全局的 VibeManager 来实现功能。
2025-06-25 17:53:16 +00:00
var autoplay_group: StringName
2025-06-18 13:48:59 +00:00
func _ready():
# 仅在游戏运行时执行
if Engine.is_editor_hint():
return
2025-06-25 17:53:16 +00:00
if autoplay_group:
switch_to(autoplay_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)
2025-06-18 13:48:59 +00:00
2025-06-25 17:53:16 +00:00
var current_group: StringName
2025-06-18 13:48:59 +00:00
## 公共方法:切换到指定的 VibeGroup。
## 可以在其他脚本(如过场动画控制器、区域触发器)中调用此方法。
## example: $VibeSfx.switch_to("event_1_vibe")
func switch_to(group_name: StringName):
2025-06-25 17:53:16 +00:00
if current_group:
AudioManager.stop_group(current_group)
current_group = group_name
AudioManager.play_group(group_name)
2025-06-18 13:48:59 +00:00
func stop():
2025-06-25 17:53:16 +00:00
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
}
]