-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioHandler.cs
More file actions
42 lines (36 loc) · 980 Bytes
/
AudioHandler.cs
File metadata and controls
42 lines (36 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEngine;
using System;
namespace Framework.Utilities.AudioManager
{
public class AudioHandle
{
AudioSource _src;
Action<AudioSource> _release;
internal AudioHandle(AudioSource src, Action<AudioSource> release)
{
_src = src;
_release = release;
}
public bool IsPlaying => _src != null && _src.isPlaying;
// 关闭音效,并且调用回调函数
public void Stop()
{
if (_src == null) return;
_src.Stop();
_release?.Invoke(_src);
_src = null;
_release = null;
}
// Internal: used by manager to return when finished
internal void ReturnIfFinished()
{
if (_src == null) return;
if (!_src.isPlaying)
{
_release?.Invoke(_src);
_src = null;
_release = null;
}
}
}
}