Skip to content

Commit

Permalink
Merge branch 'SCP-SL-Plugin-YongAnTeam:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
YongAn404 authored Dec 10, 2024
2 parents 3ca3421 + 0a293f8 commit 66024af
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions Roles/MusicManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ public AudioPlayerBase Play(string musicFile, string npcName, FramePlayer source
return Play(musicFile, npcName, new TrackEvent(), source, distance, [], false, 80, false);
}
/// <summary>
/// 单独给一个人播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
/// <param name="npcName">NPC名称</param>
/// <param name="source">指定玩家</param>
/// <returns></returns>
public AudioPlayerBase Play(string musicFile, string npcName, Player source)
{
return Play(musicFile, npcName, new TrackEvent(), source, [], false, 80, false);
}
/// <summary>
/// 播放音频
/// </summary>
/// <param name="musicFile">音频文件</param>
Expand Down Expand Up @@ -154,7 +165,59 @@ public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackE
}
return audioPlayerBase;
}
/// <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="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)
{
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;
Expand Down

0 comments on commit 66024af

Please sign in to comment.