Skip to content

Commit 97d3975

Browse files
committed
紧急修复 (#31)
1 parent 91f962d commit 97d3975

File tree

3 files changed

+54
-100
lines changed

3 files changed

+54
-100
lines changed

Components/CapacityList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class CapacityList<T>(int capacity) : ICollection<T>, IEnumerable<T>, IEn
1212

1313
public int Count => list.Count;
1414

15-
public bool IsReadOnly => throw new System.NotImplementedException();
15+
public bool IsReadOnly => false;
1616

1717
public T this[int index]
1818
{

Players/HintManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private IEnumerator<float> Update()
3838
}
3939

4040
used = 1;
41-
text[used] = "<align=left>";
41+
text[used] = "<align=left><noparse>";
4242

4343
for (int i = 0; i < ChatTexts.Capacity; i++)
4444
{
@@ -60,6 +60,7 @@ private IEnumerator<float> Update()
6060
}
6161
used++;
6262
}
63+
text[used] = "</noparse>";
6364

6465
foreach (Text data in CustomText)
6566
{
@@ -94,7 +95,6 @@ private IEnumerator<float> Update()
9495
text[34] += $"<color=\"{fPlayer.CustomRolePlus.NameColor}\">{fPlayer.CustomRolePlus.Name}</color>";
9596
text[35] = fPlayer.CustomRolePlus.Description;
9697
}
97-
9898
fPlayer.ExPlayer.ShowHint($"<size=20>{string.Join("\n", text)}\n\n\n\n\n\n\n\n\n\n\n\n\n\n</size>", 2f);
9999
yield return Timing.WaitForSeconds(1f);
100100
}

Roles/MusicManager.cs

Lines changed: 51 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public sealed class MusicManager
1818
{
1919
private static readonly MusicManager instance = new();
2020

21-
private int num = 1;
21+
private uint num = 0;
2222
/// <summary>
2323
/// 获取<seealso cref="MusicManager"/>单例
2424
/// </summary>
@@ -46,7 +46,7 @@ private ReferenceHub CreateMusicNpc(string name)
4646
ReferenceHub hubNpc = newNpc.GetComponent<ReferenceHub>();
4747
NetworkServer.AddPlayerForConnection(new FakeConnection(0), newNpc);
4848
hubNpc.nicknameSync.Network_myNickSync = name;
49-
MusicNpc.Add(name, hubNpc);
49+
MusicNpc.Add($"{num++}:{name}", hubNpc);
5050
return hubNpc;
5151
}
5252

@@ -65,151 +65,105 @@ public void Stop(AudioPlayerBase playerBase)
6565
UnityEngine.Object.Destroy(npc.gameObject);
6666
}
6767
/// <summary>
68-
/// 播放音频
68+
/// 向所有玩家播放音频
6969
/// </summary>
7070
/// <param name="musicFile">音频文件</param>
7171
/// <param name="npcName">NPC名称</param>
7272
/// <returns></returns>
7373
public AudioPlayerBase Play(string musicFile, string npcName)
7474
{
75-
return Play(musicFile, npcName, new TrackEvent(), null, 0, [], false, 80, false);
75+
return Play(musicFile, npcName, -1);
7676
}
7777
/// <summary>
78-
/// 播放音频
78+
/// 向一名玩家播放音频
7979
/// </summary>
8080
/// <param name="musicFile">音频文件</param>
8181
/// <param name="npcName">NPC名称</param>
82-
/// <param name="source">传播距离检测源头玩家</param>
83-
/// <param name="distance">传播距离</param>
82+
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
8483
/// <returns></returns>
85-
public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source, float distance)
84+
public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source)
8685
{
87-
return Play(musicFile, npcName, new TrackEvent(), source, distance, [], false, 80, false);
86+
return Play(musicFile, npcName, source, 0);
8887
}
8988
/// <summary>
90-
/// 单独给一个人播放音频
89+
/// NPC向玩家播放音频
9190
/// </summary>
9291
/// <param name="musicFile">音频文件</param>
9392
/// <param name="npcName">NPC名称</param>
94-
/// <param name="source">指定玩家</param>
93+
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
9594
/// <returns></returns>
96-
public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source)
95+
public AudioPlayerBase Play(string musicFile, string npcName,float distance)
9796
{
98-
return Play(musicFile, npcName, new TrackEvent(), source, [], false, 80, false);
97+
return Play(musicFile, npcName, null, distance);
9998
}
10099
/// <summary>
101-
/// 播放音频
100+
/// 在多少米内向玩家播放音频
102101
/// </summary>
103102
/// <param name="musicFile">音频文件</param>
104103
/// <param name="npcName">NPC名称</param>
105-
/// <param name="trackEvent">播放事件,可以是 null</param>
106-
/// <param name="source">传播距离检测源头玩家,如果是 null 所有人都将听到</param>
107-
/// <param name="distance">传播距离(源头玩家为 null 将无效)</param>
108-
/// <param name="extraPlay">额外可接收音频的玩家,可以是 null</param>
109-
/// <param name="isSole">是否覆盖播放</param>
110-
/// <param name="volume">音量大小</param>
111-
/// <param name="isLoop">是否循环</param>
104+
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
105+
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
112106
/// <returns></returns>
113-
public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackEvent, FramePlayer source, float distance, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false)
107+
public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source, float distance)
114108
{
115-
AudioPlayerBase audioPlayerBase = null;
116-
try
117-
{
118-
if (trackEvent.HasValue)
119-
{
120-
OnTrackLoaded += trackEvent.Value.TrackLoaded;
121-
}
122-
123-
if (!MusicNpc.TryGetValue(npcName, out ReferenceHub npc))
124-
{
125-
npc = CreateMusicNpc(npcName);
126-
audioPlayerBase = Get(npc);
127-
}
128-
else
129-
{
130-
if (!isSole)
131-
{
132-
npc = CreateMusicNpc(npcName);
133-
audioPlayerBase = Get(npc);
134-
MusicNpc.Add(num + npcName, npc);
135-
num++;
136-
}
137-
}
138-
139-
140-
if (source != null)
141-
{
142-
audioPlayerBase.AudioToPlay = FramePlayer.List.Where(p => Vector3.Distance(p.ExPlayer.Position, source.ExPlayer.Position) <= distance).Select((s) => s.ExPlayer.UserId).ToList();
143-
}
144-
else
145-
{
146-
audioPlayerBase.AudioToPlay = FramePlayer.List.Select((s) => s.ExPlayer.UserId).ToList();
147-
}
148-
149-
if (extraPlay != null)
150-
{
151-
foreach (var player in extraPlay)
152-
{
153-
audioPlayerBase.AudioToPlay.Add(player.ExPlayer.UserId);
154-
}
155-
}
156-
157-
audioPlayerBase.Enqueue($"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg", 0);
158-
audioPlayerBase.Volume = volume;
159-
audioPlayerBase.Loop = isLoop;
160-
audioPlayerBase.Play(0);
161-
}
162-
catch (Exception)
163-
{
164-
Stop(audioPlayerBase);
165-
}
166-
return audioPlayerBase;
109+
return Play(musicFile, npcName, null, source, distance, null, false, 80, false);
167110
}
168111
/// <summary>
169112
/// 播放音频
170113
/// </summary>
171114
/// <param name="musicFile">音频文件</param>
172115
/// <param name="npcName">NPC名称</param>
173-
/// <param name="trackEvent">播放事件</param>
174-
/// <param name="source">传播距离检测源头玩家</param>
175-
/// <param name="extraPlay">额外可接收音频的玩家</param>
176-
/// <param name="isSole">是否覆盖播放</param>
116+
/// <param name="trackEvent">播放事件(可null)</param>
117+
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
118+
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
119+
/// <param name="extraPlay">额外可接收音频的玩家(可null)</param>
120+
/// <param name="isSole">[弃用]是否覆盖播放</param>
177121
/// <param name="volume">音量大小</param>
178122
/// <param name="isLoop">是否循环</param>
179123
/// <returns></returns>
180-
public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent trackEvent, FramePlayer source, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false)
124+
public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackEvent, FramePlayer source, float distance, FramePlayer[] extraPlay, bool isSole = false, float volume = 80, bool isLoop = false)
181125
{
182126
AudioPlayerBase audioPlayerBase = null;
183127
try
184128
{
185-
OnTrackLoaded += trackEvent.TrackLoaded;
186-
if (!MusicNpc.TryGetValue(npcName, out ReferenceHub npc))
129+
if (trackEvent.HasValue)
187130
{
188-
npc = CreateMusicNpc(npcName);
189-
audioPlayerBase = Get(npc);
131+
OnTrackLoaded += trackEvent.Value.TrackLoaded;
190132
}
191-
else
133+
134+
ReferenceHub npc = CreateMusicNpc(npcName);
135+
audioPlayerBase = Get(npc);
136+
137+
if (distance != -1)
192138
{
193-
if (!isSole)
139+
if (source != null)
194140
{
195-
npc = CreateMusicNpc(npcName);
196-
audioPlayerBase = Get(npc);
197-
MusicNpc.Add(num + npcName, npc);
198-
num++;
141+
if (distance == 0)
142+
{
143+
audioPlayerBase.BroadcastTo.Add(npc.PlayerId);
144+
}
145+
else
146+
{
147+
audioPlayerBase.BroadcastTo = FramePlayer.List.Where(p => Vector3.Distance(p.ExPlayer.Position, source.ExPlayer.Position) <= distance).Select((s) => s.ExPlayer.Id).ToList();
148+
}
199149
}
200-
}
201150

202-
if (extraPlay != null)
203-
{
204-
audioPlayerBase.AudioToPlay = extraPlay.Select((s) => { return s.ExPlayer.UserId; }).ToList();
151+
if (extraPlay != null)
152+
{
153+
foreach (var player in extraPlay)
154+
{
155+
if (!audioPlayerBase.BroadcastTo.Contains(player.ExPlayer.Id))
156+
{
157+
audioPlayerBase.BroadcastTo.Add(player.ExPlayer.Id);
158+
}
159+
}
160+
}
205161
}
206162

207-
audioPlayerBase.AudioToPlay.Add(source.ExPlayer.UserId);
208-
209-
audioPlayerBase.Enqueue($"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg", 0);
163+
audioPlayerBase.CurrentPlay = $"{Paths.Plugins}/{Server.Port}/YongAnPluginData/{musicFile}.ogg";
210164
audioPlayerBase.Volume = volume;
211165
audioPlayerBase.Loop = isLoop;
212-
audioPlayerBase.Play(0);
166+
audioPlayerBase.Play(-1);
213167
}
214168
catch (Exception)
215169
{

0 commit comments

Comments
 (0)