Skip to content

Commit f9f6cce

Browse files
committed
refactor(Sound): 简化属性访问器的代码格式
统一使用简洁的单行表达式替换多行属性访问器,提高代码可读性
1 parent 304048b commit f9f6cce

File tree

1 file changed

+34
-105
lines changed

1 file changed

+34
-105
lines changed

Runtime/Sound/DefaultSoundAgentHelper.cs

Lines changed: 34 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -32,202 +32,124 @@ public class DefaultSoundAgentHelper : SoundAgentHelperBase
3232
/// </summary>
3333
public override bool IsPlaying
3434
{
35-
get
36-
{
37-
return m_AudioSource.isPlaying;
38-
}
35+
get { return m_AudioSource.isPlaying; }
3936
}
4037

4138
/// <summary>
4239
/// 获取声音长度。
4340
/// </summary>
4441
public override float Length
4542
{
46-
get
47-
{
48-
return m_AudioSource.clip != null ? m_AudioSource.clip.length : 0f;
49-
}
43+
get { return m_AudioSource.clip != null ? m_AudioSource.clip.length : 0f; }
5044
}
5145

5246
/// <summary>
5347
/// 获取或设置播放位置。
5448
/// </summary>
5549
public override float Time
5650
{
57-
get
58-
{
59-
return m_AudioSource.time;
60-
}
61-
set
62-
{
63-
m_AudioSource.time = value;
64-
}
51+
get { return m_AudioSource.time; }
52+
set { m_AudioSource.time = value; }
6553
}
6654

6755
/// <summary>
6856
/// 获取或设置是否静音。
6957
/// </summary>
7058
public override bool Mute
7159
{
72-
get
73-
{
74-
return m_AudioSource.mute;
75-
}
76-
set
77-
{
78-
m_AudioSource.mute = value;
79-
}
60+
get { return m_AudioSource.mute; }
61+
set { m_AudioSource.mute = value; }
8062
}
8163

8264
/// <summary>
8365
/// 获取或设置是否循环播放。
8466
/// </summary>
8567
public override bool Loop
8668
{
87-
get
88-
{
89-
return m_AudioSource.loop;
90-
}
91-
set
92-
{
93-
m_AudioSource.loop = value;
94-
}
69+
get { return m_AudioSource.loop; }
70+
set { m_AudioSource.loop = value; }
9571
}
9672

9773
/// <summary>
9874
/// 获取或设置声音优先级。
9975
/// </summary>
10076
public override int Priority
10177
{
102-
get
103-
{
104-
return 128 - m_AudioSource.priority;
105-
}
106-
set
107-
{
108-
m_AudioSource.priority = 128 - value;
109-
}
78+
get { return 128 - m_AudioSource.priority; }
79+
set { m_AudioSource.priority = 128 - value; }
11080
}
11181

11282
/// <summary>
11383
/// 获取或设置音量大小。
11484
/// </summary>
11585
public override float Volume
11686
{
117-
get
118-
{
119-
return m_AudioSource.volume;
120-
}
121-
set
122-
{
123-
m_AudioSource.volume = value;
124-
}
87+
get { return m_AudioSource.volume; }
88+
set { m_AudioSource.volume = value; }
12589
}
12690

12791
/// <summary>
12892
/// 获取或设置声音音调。
12993
/// </summary>
13094
public override float Pitch
13195
{
132-
get
133-
{
134-
return m_AudioSource.pitch;
135-
}
136-
set
137-
{
138-
m_AudioSource.pitch = value;
139-
}
96+
get { return m_AudioSource.pitch; }
97+
set { m_AudioSource.pitch = value; }
14098
}
14199

142100
/// <summary>
143101
/// 获取或设置声音立体声声相。
144102
/// </summary>
145103
public override float PanStereo
146104
{
147-
get
148-
{
149-
return m_AudioSource.panStereo;
150-
}
151-
set
152-
{
153-
m_AudioSource.panStereo = value;
154-
}
105+
get { return m_AudioSource.panStereo; }
106+
set { m_AudioSource.panStereo = value; }
155107
}
156108

157109
/// <summary>
158110
/// 获取或设置声音空间混合量。
159111
/// </summary>
160112
public override float SpatialBlend
161113
{
162-
get
163-
{
164-
return m_AudioSource.spatialBlend;
165-
}
166-
set
167-
{
168-
m_AudioSource.spatialBlend = value;
169-
}
114+
get { return m_AudioSource.spatialBlend; }
115+
set { m_AudioSource.spatialBlend = value; }
170116
}
171117

172118
/// <summary>
173119
/// 获取或设置声音最大距离。
174120
/// </summary>
175121
public override float MaxDistance
176122
{
177-
get
178-
{
179-
return m_AudioSource.maxDistance;
180-
}
123+
get { return m_AudioSource.maxDistance; }
181124

182-
set
183-
{
184-
m_AudioSource.maxDistance = value;
185-
}
125+
set { m_AudioSource.maxDistance = value; }
186126
}
187127

188128
/// <summary>
189129
/// 获取或设置声音多普勒等级。
190130
/// </summary>
191131
public override float DopplerLevel
192132
{
193-
get
194-
{
195-
return m_AudioSource.dopplerLevel;
196-
}
197-
set
198-
{
199-
m_AudioSource.dopplerLevel = value;
200-
}
133+
get { return m_AudioSource.dopplerLevel; }
134+
set { m_AudioSource.dopplerLevel = value; }
201135
}
202136

203137
/// <summary>
204138
/// 获取或设置声音代理辅助器所在的混音组。
205139
/// </summary>
206140
public override AudioMixerGroup AudioMixerGroup
207141
{
208-
get
209-
{
210-
return m_AudioSource.outputAudioMixerGroup;
211-
}
212-
set
213-
{
214-
m_AudioSource.outputAudioMixerGroup = value;
215-
}
142+
get { return m_AudioSource.outputAudioMixerGroup; }
143+
set { m_AudioSource.outputAudioMixerGroup = value; }
216144
}
217145

218146
/// <summary>
219147
/// 重置声音代理事件。
220148
/// </summary>
221149
public override event EventHandler<ResetSoundAgentEventArgs> ResetSoundAgent
222150
{
223-
add
224-
{
225-
m_ResetSoundAgentEventHandler += value;
226-
}
227-
remove
228-
{
229-
m_ResetSoundAgentEventHandler -= value;
230-
}
151+
add { m_ResetSoundAgentEventHandler += value; }
152+
remove { m_ResetSoundAgentEventHandler -= value; }
231153
}
232154

233155
/// <summary>
@@ -283,13 +205,20 @@ public override void Pause(float fadeOutSeconds)
283205
SetPause(true);
284206
}
285207
}
286-
private void SetPause(bool _pause) {
208+
209+
private void SetPause(bool _pause)
210+
{
287211
m_IsPause = _pause;
288212
if (m_IsPause)
213+
{
289214
m_AudioSource.Pause();
215+
}
290216
else
217+
{
291218
m_AudioSource.UnPause();
219+
}
292220
}
221+
293222
/// <summary>
294223
/// 恢复播放声音。
295224
/// </summary>

0 commit comments

Comments
 (0)