SoundService

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法建立
服務

一個服務,決定在體驗中如何 Sounds 播放的各種方面。SoundService 也常用來儲存SoundGroups,雖然這對群組的運作不是必需的。

SoundService 屬性,例如 AmbientReverb , DistanceFactor , DopplerScaleRolloffScale 可用於更改所有 Sounds 在體驗中播放的方式,而 SetListener() 函數允許您設置聲音被聽到的位置。

範例程式碼

在 執行此樣本的代碼時,將更改 標籤的 屬性,當玩家在 標籤內時。

要添加或移除標籤和回音類型,請變更「回音標籤」表中的項目。

動態重疊系統

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

概要

屬性

方法

屬性

AmbientReverb

平行讀取

CharacterSoundsUseNewApi

外掛程式安全性
平行讀取

DefaultListenerLocation

外掛程式安全性
平行讀取

DistanceFactor

平行讀取

DopplerScale

平行讀取

RespectFilteringEnabled

平行讀取

RolloffScale

平行讀取

VolumetricAudio

無法建立指令碼
平行讀取

方法

GetListener


返回

OpenAttenuationCurveEditor

()
外掛程式安全性

參數

selectedCurveObjects: Instances
預設值:""

返回

()

OpenDirectionalCurveEditor

()
外掛程式安全性

參數

selectedCurveObjects: Instances
預設值:""

返回

()

PlayLocalSound

()

參數

sound: Instance
預設值:""

返回

()

SetListener

()

參數

listenerType: Enum.ListenerType
預設值:""
listener: Tuple
預設值:""

返回

()

活動