学习
引擎类
SoundService
无法创建
服务

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


代码示例
动态混响系统
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,
}
-- 收集部件并按标签对它们进行分组
local parts = {}
for reverbTag, reverbType in pairs(reverbTags) do
for _, part in pairs(CollectionService:GetTagged(reverbTag)) do
parts[part] = reverbType
end
end
-- 检查一个位置是否在部件的范围内的函数
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
-- 默认为无混响
local newReverbType = Enum.ReverbType.NoReverb
if character and character.PrimaryPart then
local position = character.PrimaryPart.Position
-- 遍历所有索引的部件
for part, type in pairs(parts) do
-- 查看角色是否在其中
if positionInPart(part, position) then
-- 如果是,选择该混响类型
newReverbType = type
break
end
end
end
-- 如果混响类型已更改,则设置混响类型
if newReverbType ~= reverbType then
SoundService.AmbientReverb = newReverbType
reverbType = newReverbType
end
end

API 参考
属性
AcousticSimulationEnabled
读取并联
功能: Audio
SoundService.AcousticSimulationEnabled:boolean

AmbientReverb
读取并联
功能: Audio
SoundService.AmbientReverb:Enum.ReverbType

CharacterSoundsUseNewApi
插件安全性
读取并联
功能: Audio
SoundService.CharacterSoundsUseNewApi:Enum.RolloutState

DefaultListenerLocation
插件安全性
读取并联
功能: Audio
SoundService.DefaultListenerLocation:Enum.ListenerLocation

DistanceFactor
读取并联
功能: Audio
SoundService.DistanceFactor:number

DopplerScale
读取并联
功能: Audio
SoundService.DopplerScale:number

ListenerCFrame
读取并联
功能: Audio
SoundService.ListenerCFrame:CFrame

ListenerObject
读取并联
功能: Audio
SoundService.ListenerObject:Instance

ListenerType
读取并联
功能: Audio
SoundService.ListenerType:Enum.ListenerType

RespectFilteringEnabled
读取并联
功能: Audio
SoundService.RespectFilteringEnabled:boolean

RolloffScale
读取并联
功能: Audio
SoundService.RolloffScale:number

VolumetricAudio
不可写入脚本
读取并联
功能: Audio
SoundService.VolumetricAudio:Enum.VolumetricAudio

方法
GetListener
功能: Audio
SoundService:GetListener():Tuple
返回

GetMixerTime
功能: Audio
SoundService:GetMixerTime():number
返回

OpenAttenuationCurveEditor
插件安全性
功能: Audio
SoundService:OpenAttenuationCurveEditor(selectedCurveObjects:Instances):()
参数
selectedCurveObjects:Instances
返回
()

OpenDirectionalCurveEditor
插件安全性
功能: Audio
SoundService:OpenDirectionalCurveEditor(selectedCurveObjects:Instances):()
参数
selectedCurveObjects:Instances
返回
()

PlayLocalSound
功能: Audio
SoundService:PlayLocalSound(sound:Instance):()
参数
sound:Instance
返回
()

SetListener
功能: Audio
SoundService:SetListener(
listenerType:Enum.ListenerType, listener:Tuple
):()
参数
listenerType:Enum.ListenerType
listener:Tuple
返回
()

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。