From 0a293f845f82ca593a836e788b42766f3677a9f5 Mon Sep 17 00:00:00 2001 From: XLittleLeft <96688147+XLittleLeft@users.noreply.github.com> Date: Tue, 10 Dec 2024 18:11:32 +0800 Subject: [PATCH] Update MusicManager.cs (#27) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 单独给一个玩家放音频而不操心距离到底是多少 Signed-off-by: XLittleLeft <96688147+XLittleLeft@users.noreply.github.com> --- Roles/MusicManager.cs | 63 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Roles/MusicManager.cs b/Roles/MusicManager.cs index d71c7ad..7b05647 100644 --- a/Roles/MusicManager.cs +++ b/Roles/MusicManager.cs @@ -84,6 +84,17 @@ public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source return Play(musicFile, npcName, new TrackEvent(), source, distance, [], false, 80, false); } /// + /// 单独给一个人播放音频 + /// + /// 音频文件 + /// NPC名称 + /// 指定玩家 + /// + public AudioPlayerBase Play(string musicFile, string npcName, Player source) + { + return Play(musicFile, npcName, new TrackEvent(), source, [], false, 80, false); + } + /// /// 播放音频 /// /// 音频文件 @@ -143,7 +154,59 @@ public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEv } return audioPlayerBase; } + /// + /// 播放音频 + /// + /// 音频文件 + /// NPC名称 + /// 播放事件 + /// 传播距离检测源头玩家 + /// 额外可接收音频的玩家 + /// 是否覆盖播放 + /// 音量大小 + /// 是否循环 + /// + public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEvent, FramePlayer source, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false) + { + AudioPlayerBase audioPlayerBase = null; + try + { + OnTrackLoaded += trackEvent.TrackLoaded; + if (!MusicNpc.TryGetValue(npcName, out ReferenceHub npc)) + { + npc = CreateMusicNpc(npcName); + audioPlayerBase = Get(npc); + } + else + { + if (!isSole) + { + npc = CreateMusicNpc(npcName); + audioPlayerBase = Get(npc); + MusicNpc.Add(num + npcName, npc); + num++; + } + } + + if (extraPlay != null) + { + audioPlayerBase.AudioToPlay = extraPlay.Select((s) => { return s.ExPlayer.UserId; }).ToList(); + } + audioPlayerBase.AudioToPlay.Add(source.UserId); + + audioPlayerBase.Enqueue($"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg", 0); + audioPlayerBase.Volume = volume; + audioPlayerBase.Loop = isLoop; + audioPlayerBase.Play(0); + } + catch (Exception) + { + Stop(audioPlayerBase); + } + return audioPlayerBase; + } + public readonly struct TrackEvent(TrackLoaded trackLoaded) { public TrackLoaded TrackLoaded { get; } = trackLoaded;