一种服务,决定体验中 Sounds 播放的各个方面。SoundService 也常用于存储SoundGroups,尽管这对群组的工作不是必需的。
SoundService 属性,例如 AmbientReverb , DistanceFactor , DopplerScale 和 RolloffScale 可用于改变所有 Sounds 在体验中播放的方式,而 SetListener() 函数允许您设置从哪里听到声音的位置。
代码示例
The code in this sample, when ran from a LocalScript, will change the SoundService.AmbientReverb property of SoundService when the player is inside a BasePart tagged using CollectionService.
To add or remove tags and reverb types, change the entries in the 'reverbTags' table.
local Players = game:GetService("Players")
local CollectionService = game:GetService("CollectionService")
local SoundService = game:GetService("SoundService")
local localPlayer = Players.LocalPlayer
local reverbTags = {
["reverb_Cave"] = Enum.ReverbType.Cave,
}
-- collect parts and group them by tag
local parts = {}
for reverbTag, reverbType in pairs(reverbTags) do
for _, part in pairs(CollectionService:GetTagged(reverbTag)) do
parts[part] = reverbType
end
end
-- function to check if a position is within a part's extents
local function positionInPart(part, position)
local extents = part.Size / 2
local offset = part.CFrame:PointToObjectSpace(position)
return offset.x < extents.x and offset.y < extents.y and offset.z < extents.z
end
local reverbType = SoundService.AmbientReverb
while true do
task.wait()
if not localPlayer then
return
end
local character = localPlayer.Character
-- default to no reverb
local newReverbType = Enum.ReverbType.NoReverb
if character and character.PrimaryPart then
local position = character.PrimaryPart.Position
-- go through all the indexed parts
for part, type in pairs(parts) do
-- see if the character is within them
if positionInPart(part, position) then
-- if so, pick that reverb type
newReverbType = type
break
end
end
end
-- set the reverb type if it has changed
if newReverbType ~= reverbType then
SoundService.AmbientReverb = newReverbType
reverbType = newReverbType
end
end
概要
属性
由 SoundService 使用的环境音环境预设。
决定在哪里(如果任何地方)默认放置 AudioListener 。
在计算音量衰减时,由 考虑的螺柱数量,当父辈转到 或 时。
由于扰动效应,一个 Sound 的音调变化的程度。
设置客户端的播放是否会复制到服务器。 Sound
设置音量降低的速度 Sound 。
方法
返回当前 SoundService 列表器类型和设为列表器的内容。
在本地播放 Sound,意味着声音只会被调用此方法的客户端听到,无论它属于哪个父辈。
将收听器设置为 SoundService。
属性
AmbientReverb
每个 Enum.ReverbType 此属性的选项对应于 FMOD 音效引擎中可用的预设。例如,当 AmbientReverb 设置为 Enum.ReverbType.Hangar 时,声音会以不同的方式回荡,模拟身处大型封闭空间。
更改 AmbientReverb 会影响 Roblox 音效引擎使用的以下属性
- 衰减时间。
- 初始反射延迟时间。
- 与初始反射时间相对的延迟迟缓回声时间。
- 参考高频。
- 高频到中频衰变时间比率。
- 控制迟期回声衰减中的回声密度的值。
- 控制迟滞衰减中模态密度的值。
- 参考低频。
- 低频时相对房间效果等级。
- 在高频时相对房间效果等级。
- 与房间效果相对的早期反射等级。
- 中等频率下房间效果等级。
CharacterSoundsUseNewApi
DistanceFactor
在计算音量衰减时,由 考虑的螺柱数量,当父辈转到 或 时。
默认情况下,这个属性是 3.33 , 即表示一个计量单位被视为 3.33 格以实现音量减少。随着 DistanceFactor 的增加,音量会逐渐减弱。
建议您仅在体验使用不同比缩放时更改此属性。例如,当使用更大的自定义角色时,您可能想要减少 DistanceFactor 。
DopplerScale
这个属性决定了一个 Sound 的音高是否由于扰动效应而变化的程度,这是一种现象,使音高的音高随着音源和观察者的移动或靠近而变化。仅影响那些作为父级的 Sounds 或 BasePart 或 Attachment 的子级。
提高这个值会增强 Doppler 效果的影响,而减少它会最大限度地减少它。默认情况下,此属性的值为 1 .
RespectFilteringEnabled
该属性决定是否 Sound 播放从客户端复制到服务器,从而也从服务器。换言之,当 LocalScript 调用 Play() 和此属性为 true 时,音效只会在各自的客户端播放。如果此属性是 false,其他客户端也会听到声音。
默认值为 true , 意味着过滤已启用。
RolloffScale
设置音量降低的速度 Sound 。随着距离从收听者到声音的距离增加,音量的衰减速度越快,RolloffScale 越高。
请注意,此属性仅适用于 Sounds 其 RollOffMode 属性设置为 Inverse (默认)或 InverseTapered 。Linear和LinearSquare模式使用不受此属性影响的不同衰减模型。此属性也不会对 Sounds 产生影响,这些不属于 BasePart 或 Attachment 的父辈。
VolumetricAudio
方法
GetListener
该方法返回当前列听器类型 SoundService 以及设为列听器的内容,即体验中的音频被玩家“听到”的点。默认情况下,收听器设置为 Workspace.CurrentCamera。收听器可以使用 SetListener() 更改。
第一个返回的结果是收听者的 Enum.ListenerType ,第二个结果取决于那种输入:
<th>描述</th></tr></thead><tbody><tr><td><code>Enum.ListenerType.摄像头</code></td><td>不返回一个收听器对象作为 <code>类。Workspace.CurrentCamera|CurrentCamera</code> 始终使用。</td></tr><tr><td><code>Enum.ListenerType.CFrame</code></td><td>返回 <code>Datatype.CFrame</code> 在 <code>Class.SoundService:SetListener()|SetListener()</code> 中使用的类型。</td></tr><tr><td><code>Enum.ListenerType.ObjectPosition</code></td><td>返回 <code>Class.BasePart</code> 在 <code>Class.SoundService:SetListener()|SetListener()</code> 中使用的。</td></tr><tr><td><code>Enum.ListenerType.ObjectCFrame</code></td><td>返回 <code>Class.BasePart</code> 在 <code>Class.SoundService:SetListener()|SetListener()</code> 中使用的。</td></tr></tbody>
收听器类型 |
---|
返回
当前 Enum.ListenerType 和听众被设置为什么。听众可以是 BasePart 、 CFrame 或 nil 。
OpenAttenuationCurveEditor
参数
返回
OpenDirectionalCurveEditor
参数
返回
PlayLocalSound
在本地播放 Sound,意味着声音只会被调用此方法的客户端听到,无论它属于哪个父辈。这种方法最适合在 Studio 客户端本地播放 Sound,例如在一个 Script 中为一个 Plugin 播放。
参数
返回
SetListener
设置客户端使用的收听器,即音频在体验中“被听到”的点。对于 Sounds 被父辈到一个 BasePart 或 Attachment ,收听器会影响播放声音的音量和左右平衡。
默认情况下,收听器设置为 Workspace.CurrentCamera ,但可以使用一系列不同类型的收听器。
收听器可以使用 GetListener() 来检索。
参数
收听器的 Enum.ListenerType。
取决于 Enum.ListenerType .使用 BasePart 为 Enum.ListenerType.ObjectPosition 或 Enum.ListenerType.ObjectCFrame , 使用 CFrame 为 Enum.ListenerType.CFrame , 或使用 nil 为 Enum.ListenerType.Camera 。