4
4
using SCPSLAudioApi . AudioCore ;
5
5
using System ;
6
6
using System . Collections . Generic ;
7
+ using System . IO ;
7
8
using System . Linq ;
9
+ using System . Net . Http ;
10
+ using System . Threading . Tasks ;
8
11
using UnityEngine ;
9
12
using YongAnFrame . Players ;
10
13
using static SCPSLAudioApi . AudioCore . AudioPlayerBase ;
@@ -172,10 +175,74 @@ public AudioPlayerBase Play(string musicFile, string npcName, TrackEvent? trackE
172
175
}
173
176
return audioPlayerBase ;
174
177
}
175
-
176
- public readonly struct TrackEvent ( TrackLoaded trackLoaded )
178
+
179
+ /// <summary>
180
+ /// 播放音频(Url)
181
+ /// </summary>
182
+ /// <param name="musicUrl">音频文件</param>
183
+ /// <param name="npcName">NPC名称</param>
184
+ /// <param name="trackEvent">播放事件(可null)</param>
185
+ /// <param name="source">传播距离检测源头玩家(可null,null时是NPC)</param>
186
+ /// <param name="distance">传播距离(-1时是全部玩家,0时是源头玩家)</param>
187
+ /// <param name="extraPlay">额外可接收音频的玩家(可null)</param>
188
+ /// <param name="isSole">[弃用]是否覆盖播放</param>
189
+ /// <param name="volume">音量大小</param>
190
+ /// <param name="isLoop">是否循环</param>
191
+ /// <returns></returns>
192
+ public AudioPlayerBase PlayUrl ( string musicUrl , string npcName , TrackEvent ? trackEvent , FramePlayer source , float distance , FramePlayer [ ] extraPlay , bool isSole = false , float volume = 80 , bool isLoop = false )
177
193
{
178
- public TrackLoaded TrackLoaded { get ; } = trackLoaded ;
194
+ AudioPlayerBase audioPlayerBase = null ;
195
+ try
196
+ {
197
+ if ( trackEvent . HasValue )
198
+ {
199
+ OnTrackLoaded += trackEvent . Value . TrackLoaded ;
200
+ }
201
+
202
+ ReferenceHub npc = CreateMusicNpc ( npcName ) ;
203
+ audioPlayerBase = Get ( npc ) ;
204
+
205
+ if ( distance != - 1 )
206
+ {
207
+ if ( source != null )
208
+ {
209
+ if ( distance == 0 )
210
+ {
211
+ audioPlayerBase . BroadcastTo . Add ( npc . PlayerId ) ;
212
+ }
213
+ else
214
+ {
215
+ audioPlayerBase . BroadcastTo = FramePlayer . List . Where ( p => Vector3 . Distance ( p . ExPlayer . Position , source . ExPlayer . Position ) <= distance ) . Select ( ( s ) => s . ExPlayer . Id ) . ToList ( ) ;
216
+ }
217
+ }
218
+
219
+ if ( extraPlay != null )
220
+ {
221
+ foreach ( var player in extraPlay )
222
+ {
223
+ if ( ! audioPlayerBase . BroadcastTo . Contains ( player . ExPlayer . Id ) )
224
+ {
225
+ audioPlayerBase . BroadcastTo . Add ( player . ExPlayer . Id ) ;
226
+ }
227
+ }
228
+ }
229
+ }
230
+
231
+ audioPlayerBase . CurrentPlay = musicUrl ;
232
+ audioPlayerBase . Volume = volume ;
233
+ audioPlayerBase . Loop = isLoop ;
234
+ audioPlayerBase . AllowUrl = true ;
235
+ audioPlayerBase . Play ( - 1 ) ;
236
+ }
237
+ catch ( Exception )
238
+ {
239
+ Stop ( audioPlayerBase ) ;
240
+ }
241
+ return audioPlayerBase ;
179
242
}
180
243
}
181
- }
244
+ public readonly struct TrackEvent ( TrackLoaded trackLoaded )
245
+ {
246
+ public TrackLoaded TrackLoaded { get ; } = trackLoaded ;
247
+ }
248
+ }
0 commit comments