Merge remote-tracking branch 'origin/demo'

This commit is contained in:
cakipaul 2025-07-24 21:28:59 +08:00
commit 533e373e6d
3 changed files with 40 additions and 8 deletions

View File

@ -17,13 +17,15 @@ var bgm_dict = {}
func _ready() -> void:
for i in range(5):
var sfx_player = RandomAudioStreamPlayer.new()
sfx_players.append(sfx_player)
sfx_player.bus = "game_sfx"
add_child(sfx_player)
_create_and_add_new_player(i)
if Engine.is_editor_hint():
_reload_groups()
func _create_and_add_new_player(index: int) -> void:
var sfx_player = RandomAudioStreamPlayer.new()
sfx_player.bus = "game_sfx"
add_child(sfx_player)
sfx_players.insert(index, sfx_player)
func _reload_groups() -> void:
VIBE_GROUPS.clear()
@ -34,6 +36,21 @@ func _reload_groups() -> void:
printerr("VibeGroup has no name: ", group)
func stop_stream(stream: AudioStream, duration := 1.0) -> void:
for i in sfx_players.size():
var player = sfx_players[i]
if player.stream == stream:
if duration > 0:
# ease 过程将它独立拎出来
sfx_players.remove_at(i)
_create_and_add_new_player(i)
var tween = create_tween()
tween.tween_property(player, "volume_linear", 0.0, duration)
tween.tween_callback(player.queue_free)
else:
player.stop()
func play_sfx(sfx: AudioStream, db := 1.0) -> void:
sfx_players[sfx_players_idx].stream = sfx
sfx_players[sfx_players_idx].volume_db = db

View File

@ -34,6 +34,7 @@ func _ready() -> void:
SceneManager.ground_transition_pre_paused.connect(_on_ground_transition_pre_paused)
SceneManager.pause_counter_updated.connect(_on_pause_counter_updated)
var playing_on_debugging_paused = false
@ -43,7 +44,10 @@ func _on_pause_counter_updated() -> void:
func _set_up_process_mode_by_mode():
# 如果是 debug panel则 pause
if mode == "场景背景音" and (SceneManager.is_node_ready() and not SceneManager.pause_counter_arr.has("debugging")):
if (
mode == "场景背景音"
and (SceneManager.is_node_ready() and not SceneManager.pause_counter_arr.has("debugging"))
):
process_mode = Node.PROCESS_MODE_ALWAYS
else:
if SceneManager.is_node_ready() and SceneManager.pause_counter_arr.has("debugging"):
@ -86,9 +90,15 @@ func resart(ease_duration := 1.0):
# queue free 导致 sfx 无法播放,使用全局声源
# 注意需要手动调用 global_stop, 否则不会自动停止
func global_play() -> void:
AudioManager.stop_stream(stream)
if stream:
AudioManager.play_sfx(stream)
AudioManager.play_sfx(stream, volume_db)
func global_stop(duration := 1.5) -> void:
AudioManager.stop_stream(stream, duration)
func easing_kill(duration: float = 2.0) -> Tween:
@ -153,3 +163,4 @@ func _get(property: StringName) -> Variant:
elif property == "感应玩家操作":
return scene_sense_player_mov
return null

View File

@ -129,7 +129,7 @@ func game_intro() -> void:
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_谈论鬼差与猫鼠游戏")
await DialogueManager.dialogue_ended
# BGM 开始后小段对话
$"Sfx猫鼠游戏".play()
$"Sfx猫鼠游戏".global_play()
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_猫鼠游戏BGM开始")
await DialogueManager.dialogue_ended
# 重置镜头
@ -290,7 +290,7 @@ func game_restart():
await Util.wait(1.0)
# 开始跑
SceneManager.release_player()
$"Sfx猫鼠游戏".set("parameters/switch_to_clip", "Intro")
$"Sfx猫鼠游戏".global_play()
DialogueManager.show_dialogue_balloon(dialogue_c01, "c01_s06_猫鼠游戏倒计时")
await Util.wait(1.5)
_kids_start_run()
@ -371,6 +371,10 @@ func transport_player_to_next_scene(win: bool):
SceneManager.pop_debug_dialog_info("音效", "猫鼠游戏失败,传送下一场景")
func _exit_tree() -> void:
$"Sfx猫鼠游戏".global_stop(3.0)
# var s07_ground := preload("res://scene/ground/scene/c01/s07_书店外.tscn")
# var s07_ground_node = s07_ground.instantiate()