54 lines
1.7 KiB
GDScript3
54 lines
1.7 KiB
GDScript3
|
@tool
|
||
|
class_name VibeSfx
|
||
|
extends Node
|
||
|
|
||
|
## VibeSfx.gd
|
||
|
## 场景中的环境音效控制器节点(“遥控器”)。
|
||
|
## 你可以将此节点放置在任何场景中,用于配置和触发不同的 VibeGroup。
|
||
|
## 它通过调用全局的 VibeManager 来实现功能。
|
||
|
|
||
|
# VibeGroup 库。使用字典可以方便地通过名称(如 "default", "battle")来引用不同的音轨组。
|
||
|
# 你可以在 Inspector 中配置这个字典,将名称映射到 VibeGroup.tres 资源文件。
|
||
|
@export var vibe_groups: Dictionary[String, VibeGroup] = {"default": null}
|
||
|
|
||
|
# 当此节点进入场景树时,是否自动播放指定的 VibeGroup。
|
||
|
@export var autoplay: bool = true
|
||
|
|
||
|
const autoplay_group_name := &"default"
|
||
|
|
||
|
|
||
|
func _ready():
|
||
|
# 仅在游戏运行时执行
|
||
|
if Engine.is_editor_hint():
|
||
|
return
|
||
|
|
||
|
if autoplay:
|
||
|
if vibe_groups.has(autoplay_group_name):
|
||
|
switch_to(autoplay_group_name)
|
||
|
else:
|
||
|
printerr(
|
||
|
(
|
||
|
"VibeSfx: Autoplay group '%s' not found in vibe_groups dictionary."
|
||
|
% autoplay_group_name
|
||
|
)
|
||
|
)
|
||
|
|
||
|
|
||
|
## 公共方法:切换到指定的 VibeGroup。
|
||
|
## 可以在其他脚本(如过场动画控制器、区域触发器)中调用此方法。
|
||
|
## example: $VibeSfx.switch_to("event_1_vibe")
|
||
|
func switch_to(group_name: StringName):
|
||
|
if vibe_groups.has(group_name):
|
||
|
var group_resource: VibeGroup = vibe_groups[group_name]
|
||
|
if is_instance_valid(group_resource):
|
||
|
AudioManager.play_group(group_resource)
|
||
|
else:
|
||
|
printerr("VibeSfx: Resource for group '%s' is null or invalid." % group_name)
|
||
|
else:
|
||
|
printerr("VibeSfx: Group name '%s' not found." % group_name)
|
||
|
|
||
|
|
||
|
## 公共方法:停止所有由 VibeManager 控制的环境音。
|
||
|
func stop():
|
||
|
AudioManager.stop_all()
|