From 065124bec1ed4bb7a7587b68a641b8d585a4e375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B8=E5=AE=89404?= <101850798+YongAn404@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:27:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=A7=E6=80=A5=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Components/CapacityList.cs | 2 +- Players/HintManager.cs | 4 +- Roles/MusicManager.cs | 148 +++++++++++++------------------------ 3 files changed, 54 insertions(+), 100 deletions(-) diff --git a/Components/CapacityList.cs b/Components/CapacityList.cs index 8a4b96b..ef1dff3 100644 --- a/Components/CapacityList.cs +++ b/Components/CapacityList.cs @@ -12,7 +12,7 @@ public class CapacityList(int capacity) : ICollection, IEnumerable, IEn public int Count => list.Count; - public bool IsReadOnly => throw new System.NotImplementedException(); + public bool IsReadOnly => false; public T this[int index] { diff --git a/Players/HintManager.cs b/Players/HintManager.cs index 806ae34..a7eb021 100644 --- a/Players/HintManager.cs +++ b/Players/HintManager.cs @@ -38,7 +38,7 @@ private IEnumerator Update() } used = 1; - text[used] = ""; + text[used] = ""; for (int i = 0; i < ChatTexts.Capacity; i++) { @@ -60,6 +60,7 @@ private IEnumerator Update() } used++; } + text[used] = ""; foreach (Text data in CustomText) { @@ -94,7 +95,6 @@ private IEnumerator Update() text[34] += $"{fPlayer.CustomRolePlus.Name}"; text[35] = fPlayer.CustomRolePlus.Description; } - fPlayer.ExPlayer.ShowHint($"{string.Join("\n", text)}\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 2f); yield return Timing.WaitForSeconds(1f); } diff --git a/Roles/MusicManager.cs b/Roles/MusicManager.cs index eac55c1..480f20d 100644 --- a/Roles/MusicManager.cs +++ b/Roles/MusicManager.cs @@ -18,7 +18,7 @@ public sealed class MusicManager { private static readonly MusicManager instance = new(); - private int num = 1; + private uint num = 0; /// /// 获取单例 /// @@ -46,7 +46,7 @@ private ReferenceHub CreateMusicNpc(string name) ReferenceHub hubNpc = newNpc.GetComponent(); NetworkServer.AddPlayerForConnection(new FakeConnection(0), newNpc); hubNpc.nicknameSync.Network_myNickSync = name; - MusicNpc.Add(name, hubNpc); + MusicNpc.Add($"{num++}:{name}", hubNpc); return hubNpc; } @@ -65,151 +65,105 @@ public void Stop(AudioPlayerBase playerBase) UnityEngine.Object.Destroy(npc.gameObject); } /// - /// 播放音频 + /// 向所有玩家播放音频 /// /// 音频文件 /// NPC名称 /// public AudioPlayerBase Play(string musicFile, string npcName) { - return Play(musicFile, npcName, new TrackEvent(), null, 0, [], false, 80, false); + return Play(musicFile, npcName, -1); } /// - /// 播放音频 + /// 向一名玩家播放音频 /// /// 音频文件 /// NPC名称 - /// 传播距离检测源头玩家 - /// 传播距离 + /// 传播距离检测源头玩家(可null,null时是NPC) /// - public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source, float distance) + public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source) { - return Play(musicFile, npcName, new TrackEvent(), source, distance, [], false, 80, false); + return Play(musicFile, npcName, source, 0); } /// - /// 单独给一个人播放音频 + /// NPC向玩家播放音频 /// /// 音频文件 /// NPC名称 - /// 指定玩家 + /// 传播距离(-1时是全部玩家,0时是源头玩家) /// - public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source) + public AudioPlayerBase Play(string musicFile, string npcName,float distance) { - return Play(musicFile, npcName, new TrackEvent(), source, [], false, 80, false); + return Play(musicFile, npcName, null, distance); } /// - /// 播放音频 + /// 在多少米内向玩家播放音频 /// /// 音频文件 /// NPC名称 - /// 播放事件,可以是 null - /// 传播距离检测源头玩家,如果是 null 所有人都将听到 - /// 传播距离(源头玩家为 null 将无效) - /// 额外可接收音频的玩家,可以是 null - /// 是否覆盖播放 - /// 音量大小 - /// 是否循环 + /// 传播距离检测源头玩家(可null,null时是NPC) + /// 传播距离(-1时是全部玩家,0时是源头玩家) /// - public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackEvent, FramePlayer source, float distance, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false) + public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source, float distance) { - AudioPlayerBase audioPlayerBase = null; - try - { - if (trackEvent.HasValue) - { - OnTrackLoaded += trackEvent.Value.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 (source != null) - { - audioPlayerBase.AudioToPlay = FramePlayer.List.Where(p => Vector3.Distance(p.ExPlayer.Position, source.ExPlayer.Position) <= distance).Select((s) => s.ExPlayer.UserId).ToList(); - } - else - { - audioPlayerBase.AudioToPlay = FramePlayer.List.Select((s) => s.ExPlayer.UserId).ToList(); - } - - if (extraPlay != null) - { - foreach (var player in extraPlay) - { - audioPlayerBase.AudioToPlay.Add(player.ExPlayer.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; + return Play(musicFile, npcName, null, source, distance, null, false, 80, false); } /// /// 播放音频 /// /// 音频文件 /// NPC名称 - /// 播放事件 - /// 传播距离检测源头玩家 - /// 额外可接收音频的玩家 - /// 是否覆盖播放 + /// 播放事件(可null) + /// 传播距离检测源头玩家(可null,null时是NPC) + /// 传播距离(-1时是全部玩家,0时是源头玩家) + /// 额外可接收音频的玩家(可null) + /// [弃用]是否覆盖播放 /// 音量大小 /// 是否循环 /// - public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEvent, FramePlayer source, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false) + public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackEvent, FramePlayer source, float distance, 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)) + if (trackEvent.HasValue) { - npc = CreateMusicNpc(npcName); - audioPlayerBase = Get(npc); + OnTrackLoaded += trackEvent.Value.TrackLoaded; } - else + + ReferenceHub npc = CreateMusicNpc(npcName); + audioPlayerBase = Get(npc); + + if (distance != -1) { - if (!isSole) + if (source != null) { - npc = CreateMusicNpc(npcName); - audioPlayerBase = Get(npc); - MusicNpc.Add(num + npcName, npc); - num++; + if (distance == 0) + { + audioPlayerBase.BroadcastTo.Add(npc.PlayerId); + } + else + { + audioPlayerBase.BroadcastTo = FramePlayer.List.Where(p => Vector3.Distance(p.ExPlayer.Position, source.ExPlayer.Position) <= distance).Select((s) => s.ExPlayer.Id).ToList(); + } } - } - if (extraPlay != null) - { - audioPlayerBase.AudioToPlay = extraPlay.Select((s) => { return s.ExPlayer.UserId; }).ToList(); + if (extraPlay != null) + { + foreach (var player in extraPlay) + { + if (!audioPlayerBase.BroadcastTo.Contains(player.ExPlayer.Id)) + { + audioPlayerBase.BroadcastTo.Add(player.ExPlayer.Id); + } + } + } } - audioPlayerBase.AudioToPlay.Add(source.ExPlayer.UserId); - - audioPlayerBase.Enqueue($"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg", 0); + audioPlayerBase.CurrentPlay = $"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg"; audioPlayerBase.Volume = volume; audioPlayerBase.Loop = isLoop; - audioPlayerBase.Play(0); + audioPlayerBase.Play(-1); } catch (Exception) {