@@ -21,6 +21,7 @@ public class DefaultSoundAgentHelper : SoundAgentHelperBase
2121 {
2222 private Transform m_CachedTransform = null ;
2323 private AudioSource m_AudioSource = null ;
24+ private bool m_IsPause = false ;
2425 private EntityLogic m_BindingEntityLogic = null ;
2526 private float m_VolumeWhenPause = 0f ;
2627 private bool m_ApplicationPauseFlag = false ;
@@ -31,124 +32,202 @@ public class DefaultSoundAgentHelper : SoundAgentHelperBase
3132 /// </summary>
3233 public override bool IsPlaying
3334 {
34- get { return m_AudioSource . isPlaying ; }
35+ get
36+ {
37+ return m_AudioSource . isPlaying ;
38+ }
3539 }
3640
3741 /// <summary>
3842 /// 获取声音长度。
3943 /// </summary>
4044 public override float Length
4145 {
42- get { return m_AudioSource . clip != null ? m_AudioSource . clip . length : 0f ; }
46+ get
47+ {
48+ return m_AudioSource . clip != null ? m_AudioSource . clip . length : 0f ;
49+ }
4350 }
4451
4552 /// <summary>
4653 /// 获取或设置播放位置。
4754 /// </summary>
4855 public override float Time
4956 {
50- get { return m_AudioSource . time ; }
51- set { m_AudioSource . time = value ; }
57+ get
58+ {
59+ return m_AudioSource . time ;
60+ }
61+ set
62+ {
63+ m_AudioSource . time = value ;
64+ }
5265 }
5366
5467 /// <summary>
5568 /// 获取或设置是否静音。
5669 /// </summary>
5770 public override bool Mute
5871 {
59- get { return m_AudioSource . mute ; }
60- set { m_AudioSource . mute = value ; }
72+ get
73+ {
74+ return m_AudioSource . mute ;
75+ }
76+ set
77+ {
78+ m_AudioSource . mute = value ;
79+ }
6180 }
6281
6382 /// <summary>
6483 /// 获取或设置是否循环播放。
6584 /// </summary>
6685 public override bool Loop
6786 {
68- get { return m_AudioSource . loop ; }
69- set { m_AudioSource . loop = value ; }
87+ get
88+ {
89+ return m_AudioSource . loop ;
90+ }
91+ set
92+ {
93+ m_AudioSource . loop = value ;
94+ }
7095 }
7196
7297 /// <summary>
7398 /// 获取或设置声音优先级。
7499 /// </summary>
75100 public override int Priority
76101 {
77- get { return 128 - m_AudioSource . priority ; }
78- set { m_AudioSource . priority = 128 - value ; }
102+ get
103+ {
104+ return 128 - m_AudioSource . priority ;
105+ }
106+ set
107+ {
108+ m_AudioSource . priority = 128 - value ;
109+ }
79110 }
80111
81112 /// <summary>
82113 /// 获取或设置音量大小。
83114 /// </summary>
84115 public override float Volume
85116 {
86- get { return m_AudioSource . volume ; }
87- set { m_AudioSource . volume = value ; }
117+ get
118+ {
119+ return m_AudioSource . volume ;
120+ }
121+ set
122+ {
123+ m_AudioSource . volume = value ;
124+ }
88125 }
89126
90127 /// <summary>
91128 /// 获取或设置声音音调。
92129 /// </summary>
93130 public override float Pitch
94131 {
95- get { return m_AudioSource . pitch ; }
96- set { m_AudioSource . pitch = value ; }
132+ get
133+ {
134+ return m_AudioSource . pitch ;
135+ }
136+ set
137+ {
138+ m_AudioSource . pitch = value ;
139+ }
97140 }
98141
99142 /// <summary>
100143 /// 获取或设置声音立体声声相。
101144 /// </summary>
102145 public override float PanStereo
103146 {
104- get { return m_AudioSource . panStereo ; }
105- set { m_AudioSource . panStereo = value ; }
147+ get
148+ {
149+ return m_AudioSource . panStereo ;
150+ }
151+ set
152+ {
153+ m_AudioSource . panStereo = value ;
154+ }
106155 }
107156
108157 /// <summary>
109158 /// 获取或设置声音空间混合量。
110159 /// </summary>
111160 public override float SpatialBlend
112161 {
113- get { return m_AudioSource . spatialBlend ; }
114- set { m_AudioSource . spatialBlend = value ; }
162+ get
163+ {
164+ return m_AudioSource . spatialBlend ;
165+ }
166+ set
167+ {
168+ m_AudioSource . spatialBlend = value ;
169+ }
115170 }
116171
117172 /// <summary>
118173 /// 获取或设置声音最大距离。
119174 /// </summary>
120175 public override float MaxDistance
121176 {
122- get { return m_AudioSource . maxDistance ; }
177+ get
178+ {
179+ return m_AudioSource . maxDistance ;
180+ }
123181
124- set { m_AudioSource . maxDistance = value ; }
182+ set
183+ {
184+ m_AudioSource . maxDistance = value ;
185+ }
125186 }
126187
127188 /// <summary>
128189 /// 获取或设置声音多普勒等级。
129190 /// </summary>
130191 public override float DopplerLevel
131192 {
132- get { return m_AudioSource . dopplerLevel ; }
133- set { m_AudioSource . dopplerLevel = value ; }
193+ get
194+ {
195+ return m_AudioSource . dopplerLevel ;
196+ }
197+ set
198+ {
199+ m_AudioSource . dopplerLevel = value ;
200+ }
134201 }
135202
136203 /// <summary>
137204 /// 获取或设置声音代理辅助器所在的混音组。
138205 /// </summary>
139206 public override AudioMixerGroup AudioMixerGroup
140207 {
141- get { return m_AudioSource . outputAudioMixerGroup ; }
142- set { m_AudioSource . outputAudioMixerGroup = value ; }
208+ get
209+ {
210+ return m_AudioSource . outputAudioMixerGroup ;
211+ }
212+ set
213+ {
214+ m_AudioSource . outputAudioMixerGroup = value ;
215+ }
143216 }
144217
145218 /// <summary>
146219 /// 重置声音代理事件。
147220 /// </summary>
148221 public override event EventHandler < ResetSoundAgentEventArgs > ResetSoundAgent
149222 {
150- add { m_ResetSoundAgentEventHandler += value ; }
151- remove { m_ResetSoundAgentEventHandler -= value ; }
223+ add
224+ {
225+ m_ResetSoundAgentEventHandler += value ;
226+ }
227+ remove
228+ {
229+ m_ResetSoundAgentEventHandler -= value ;
230+ }
152231 }
153232
154233 /// <summary>
@@ -201,10 +280,16 @@ public override void Pause(float fadeOutSeconds)
201280 }
202281 else
203282 {
204- m_AudioSource . Pause ( ) ;
283+ SetPause ( true ) ;
205284 }
206285 }
207-
286+ private void SetPause ( bool _pause ) {
287+ m_IsPause = _pause ;
288+ if ( m_IsPause )
289+ m_AudioSource . Pause ( ) ;
290+ else
291+ m_AudioSource . UnPause ( ) ;
292+ }
208293 /// <summary>
209294 /// 恢复播放声音。
210295 /// </summary>
@@ -213,7 +298,7 @@ public override void Resume(float fadeInSeconds)
213298 {
214299 StopAllCoroutines ( ) ;
215300
216- m_AudioSource . UnPause ( ) ;
301+ SetPause ( false ) ;
217302 if ( fadeInSeconds > 0f )
218303 {
219304 StartCoroutine ( FadeToVolume ( m_AudioSource , m_VolumeWhenPause , fadeInSeconds ) ) ;
@@ -229,6 +314,7 @@ public override void Resume(float fadeInSeconds)
229314 /// </summary>
230315 public override void Reset ( )
231316 {
317+ m_IsPause = false ;
232318 m_CachedTransform . localPosition = Vector3 . zero ;
233319 m_AudioSource . clip = null ;
234320 m_BindingEntityLogic = null ;
@@ -292,7 +378,7 @@ private void Awake()
292378
293379 private void Update ( )
294380 {
295- if ( ! m_ApplicationPauseFlag && ! IsPlaying && m_AudioSource . clip != null && m_ResetSoundAgentEventHandler != null )
381+ if ( ! m_ApplicationPauseFlag && ! m_IsPause && ! IsPlaying && m_AudioSource . clip != null && m_ResetSoundAgentEventHandler != null )
296382 {
297383 ResetSoundAgentEventArgs resetSoundAgentEventArgs = ResetSoundAgentEventArgs . Create ( ) ;
298384 m_ResetSoundAgentEventHandler ( this , resetSoundAgentEventArgs ) ;
@@ -336,7 +422,7 @@ private IEnumerator StopCo(float fadeOutSeconds)
336422 private IEnumerator PauseCo ( float fadeOutSeconds )
337423 {
338424 yield return FadeToVolume ( m_AudioSource , 0f , fadeOutSeconds ) ;
339- m_AudioSource . Pause ( ) ;
425+ SetPause ( true ) ;
340426 }
341427
342428 private IEnumerator FadeToVolume ( AudioSource audioSource , float volume , float duration )
0 commit comments