Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

紧急修复 #31

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Components/CapacityList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class CapacityList<T>(int capacity) : ICollection<T>, IEnumerable<T>, IEn

public int Count => list.Count;

public bool IsReadOnly => throw new System.NotImplementedException();
public bool IsReadOnly => false;

public T this[int index]
{
Expand Down
4 changes: 2 additions & 2 deletions Players/HintManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private IEnumerator<float> Update()
}

used = 1;
text[used] = "<align=left>";
text[used] = "<align=left><noparse>";

for (int i = 0; i < ChatTexts.Capacity; i++)
{
Expand All @@ -60,6 +60,7 @@ private IEnumerator<float> Update()
}
used++;
}
text[used] = "</noparse>";

foreach (Text data in CustomText)
{
Expand Down Expand Up @@ -94,7 +95,6 @@ private IEnumerator<float> Update()
text[34] += $"<color=\"{fPlayer.CustomRolePlus.NameColor}\">{fPlayer.CustomRolePlus.Name}</color>";
text[35] = fPlayer.CustomRolePlus.Description;
}

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);
yield return Timing.WaitForSeconds(1f);
}
Expand Down
148 changes: 51 additions & 97 deletions Roles/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public sealed class MusicManager
{
private static readonly MusicManager instance = new();

private int num = 1;
private uint num = 0;
/// <summary>
/// 获取<seealso cref="MusicManager"/>单例
/// </summary>
Expand Down Expand Up @@ -46,7 +46,7 @@ private ReferenceHub CreateMusicNpc(string name)
ReferenceHub hubNpc = newNpc.GetComponent<ReferenceHub>();
NetworkServer.AddPlayerForConnection(new FakeConnection(0), newNpc);
hubNpc.nicknameSync.Network_myNickSync = name;
MusicNpc.Add(name, hubNpc);
MusicNpc.Add($"{num++}:{name}", hubNpc);
return hubNpc;
}

Expand All @@ -65,151 +65,105 @@ public void Stop(AudioPlayerBase playerBase)
UnityEngine.Object.Destroy(npc.gameObject);
}
/// <summary>
/// 播放音频
/// 向所有玩家播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <returns></returns>
public AudioPlayerBase Play(string musicFile, string npcName)
{
return Play(musicFile, npcName, new TrackEvent(), null, 0, [], false, 80, false);
return Play(musicFile, npcName, -1);
}
/// <summary>
/// 播放音频
/// 向一名玩家播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <param name="source">传播距离检测源头玩家</param>
/// <param name="distance">传播距离</param>
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
/// <returns></returns>
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);
}
/// <summary>
/// 单独给一个人播放音频
/// NPC向玩家播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <param name="source">指定玩家</param>
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
/// <returns></returns>
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);
}
/// <summary>
/// 播放音频
/// 在多少米内向玩家播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <param name="trackEvent">播放事件,可以是 null</param>
/// <param name="source">传播距离检测源头玩家,如果是 null 所有人都将听到</param>
/// <param name="distance">传播距离(源头玩家为 null 将无效)</param>
/// <param name="extraPlay">额外可接收音频的玩家,可以是 null</param>
/// <param name="isSole">是否覆盖播放</param>
/// <param name="volume">音量大小</param>
/// <param name="isLoop">是否循环</param>
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
/// <returns></returns>
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);
}
/// <summary>
/// 播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <param name="trackEvent">播放事件</param>
/// <param name="source">传播距离检测源头玩家</param>
/// <param name="extraPlay">额外可接收音频的玩家</param>
/// <param name="isSole">是否覆盖播放</param>
/// <param name="trackEvent">播放事件(可null)</param>
/// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
/// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
/// <param name="extraPlay">额外可接收音频的玩家(可null)</param>
/// <param name="isSole">[弃用]是否覆盖播放</param>
/// <param name="volume">音量大小</param>
/// <param name="isLoop">是否循环</param>
/// <returns></returns>
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)
{
Expand Down
Loading