Skip to content

Commit c6b4010

Browse files
committed
[增加] 是否正在播放的接口
1 parent fe89552 commit c6b4010

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

Runtime/Interface/ISoundGroup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public interface ISoundGroup
4242
/// </summary>
4343
ISoundGroupHelper Helper { get; }
4444

45+
/// <summary>
46+
/// 是否正在播放声音。
47+
/// </summary>
48+
/// <param name="serialId">声音的序列编号。</param>
49+
/// <returns>正在播放则返回Ture,否则返回False,找不到指定的序列编号也会返回False</returns>
50+
bool IsPlaying(int serialId);
51+
4552
/// <summary>
4653
/// 停止所有已加载的声音。
4754
/// </summary>

Runtime/Sound/Sound/SoundManager.SoundGroup.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ public void AddSoundAgentHelper(ISoundHelper soundHelper, ISoundAgentHelper soun
121121
m_SoundAgents.Add(new SoundAgent(this, soundHelper, soundAgentHelper));
122122
}
123123

124+
/// <summary>
125+
/// 是否正在播放声音。
126+
/// </summary>
127+
/// <param name="serialId">声音的序列编号。</param>
128+
/// <returns>正在播放则返回Ture,否则返回False,找不到指定的序列编号也会返回False</returns>
129+
public bool IsPlaying(int serialId)
130+
{
131+
foreach (SoundAgent soundAgent in m_SoundAgents)
132+
{
133+
if (soundAgent.SerialId == serialId)
134+
{
135+
return soundAgent.IsPlaying;
136+
}
137+
}
138+
139+
return false;
140+
}
141+
124142
/// <summary>
125143
/// 播放声音。
126144
/// </summary>

Runtime/Sound/SoundComponent.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,28 @@ public bool IsLoadingSound(int serialId)
300300
return m_SoundManager.IsLoadingSound(serialId);
301301
}
302302

303+
/// <summary>
304+
/// 是否正在播放声音。
305+
/// </summary>
306+
/// <param name="soundGroupName">声音组名称。</param>
307+
/// <param name="serialId">声音序列编号。</param>
308+
/// <returns>正在播放则返回Ture,否则返回False,找不到指定的序列编号也会返回False。</returns>
309+
public bool IsPlaying(string soundGroupName, int serialId)
310+
{
311+
if (soundGroupName == null)
312+
{
313+
throw new GameFrameworkException("Sound group name is invalid.");
314+
}
315+
316+
var soundGroup = GetSoundGroup(soundGroupName);
317+
if (soundGroup == null)
318+
{
319+
throw new GameFrameworkException("Sound group is invalid.");
320+
}
321+
322+
return soundGroup.IsPlaying(serialId);
323+
}
324+
303325
/// <summary>
304326
/// 播放声音。
305327
/// </summary>

0 commit comments

Comments
 (0)