경험에서 플레이하는 방법의 다양한 측면을 결정하는 서비스입니다. Sounds``Class.SoundService 는 그룹이 작동하는 데 필수적이지 않기 때문에 종종 SoundGroups 을 저장하는 데 사용됩니다.
SoundService 속성(AmbientReverb, DistanceFactor, DopplerScale 및 RolloffScale)은 경험에서 모든 Sounds 플레이 방식을 변경하는 데 사용할 수 있으며, SetListener() 함수를 사용하면 소리가 들리는 위치를 설정할 수 있습니다.
코드 샘플
이 샘플의 코드는 에서 실행될 때, 플레이어가 태그를 사용하여 태그 내에 있을 때 속성을 변경합니다.
태그 및 리버브 유형을 추가하거나 제거하려면 '리버브Tags' 테이블의 항목을 변경하십시오.
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
요약
속성
SoundService에서 사용하는 환경 음향 환경 프리셋.
기본적으로 배치할 AudioListener 장소를 결정합니다(있는 경우).
용량 감소를 계산할 때 부모에게 전달된 또는 에 대한 스터드 수가 미터로 간주되는 횟수.
Doppler 효과로 인해 피치가 Sound 변화하는 정도.
클라이언트에서 재생하는 Sound 이 서버에 복제되는지 여부를 설정합니다.
Sound 볼륨이 얼마나 빨리 감소하는지 설정합니다.
메서드
현재 SoundService 리스너 유형과 리스너로 설정된 것을 반환합니다.
로컬에서 Sound 재생하여 소리가 이 메서드를 호출하는 클라이언트에만 들릴 수 있으며, 부모로 지정된 위치와 상관없이 합니다.
리스너를 SoundService 설정합니다.