@rbxts/sound-manager 2.3.0 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/out/core/createSoundRegistry.d.ts +12 -7
- package/out/core/createSoundRegistry.luau +220 -42
- package/out/core/createSpatialHandle.luau +6 -0
- package/out/core/options.d.ts +8 -0
- package/out/createAudioListener.d.ts +8 -0
- package/out/createAudioListener.luau +39 -0
- package/out/index.d.ts +1 -0
- package/out/init.luau +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,11 +36,11 @@ npm install @rbxts/sound-manager
|
|
|
36
36
|
|
|
37
37
|
## 🚀 Quick Start
|
|
38
38
|
|
|
39
|
-
[See the Documentation ->](https://dev-lukas0.github.io/Sound-Manager
|
|
39
|
+
[See the Documentation ->](https://dev-lukas0.github.io/Sound-Manager/)
|
|
40
40
|
|
|
41
41
|
### ⚡ Starting with Sound Manager
|
|
42
42
|
|
|
43
|
-
Sound-Manager uses [`createSoundRegistry`]() and [`createSoundCategoryRegistry`]() to create sounds and categories.
|
|
43
|
+
Sound-Manager uses [`createSoundRegistry`](https://dev-lukas0.github.io/Sound-Manager/docs/reference/create-sound-registry) and [`createSoundCategoryRegistry`](https://dev-lukas0.github.io/Sound-Manager/docs/reference/create-sound-category-registry) to create sounds and categories.
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
46
|
import { createSoundRegistry } from "@rbxts/sound-manager";
|
|
@@ -11,24 +11,29 @@ export declare function createSoundRegistry<T extends Record<string, SoundOption
|
|
|
11
11
|
emitters: BasePart[];
|
|
12
12
|
}) => void;
|
|
13
13
|
preloadAll: () => void;
|
|
14
|
-
load: (name: keyof T
|
|
14
|
+
load: (name: keyof T, spatial?: {
|
|
15
|
+
emitters: BasePart[];
|
|
16
|
+
}) => SoundHandle | undefined;
|
|
15
17
|
fadeIn: (soundName: keyof T, duration: number, volume: number, spatial?: {
|
|
16
18
|
emitters: BasePart[];
|
|
17
19
|
}) => void;
|
|
18
20
|
fadeOut: (soundName: keyof T, duration: number, targetVolume?: number, spatial?: {
|
|
19
21
|
emitters: BasePart[];
|
|
20
22
|
}) => void;
|
|
21
|
-
reset: (sound: keyof T) => void;
|
|
22
|
-
setTimePosition: (sound: keyof T, timePosition: number) => void;
|
|
23
|
-
stopAll: (reset?: true) => void;
|
|
23
|
+
reset: (sound: keyof T, spatial?: boolean) => void;
|
|
24
|
+
setTimePosition: (sound: keyof T, timePosition: number, spatial?: boolean) => void;
|
|
25
|
+
stopAll: (reset?: true, spatial?: boolean) => void;
|
|
24
26
|
preload: (sound: keyof T) => void;
|
|
25
|
-
setGlobalVolume: (volume: number) => void;
|
|
27
|
+
setGlobalVolume: (volume: number, spatial?: boolean) => void;
|
|
26
28
|
setVolume: (sound: keyof T, volume: number, spatial?: {
|
|
27
29
|
emitters: BasePart[];
|
|
28
30
|
}) => void;
|
|
29
|
-
resetAll: (sound: keyof T) => void;
|
|
31
|
+
resetAll: (sound: keyof T, spatial?: boolean) => void;
|
|
30
32
|
onEnd: (sound: keyof T, callback: () => void, spatial?: {
|
|
31
33
|
emitters: BasePart[];
|
|
32
34
|
}) => void;
|
|
33
|
-
isPlaying: (sound: keyof T) => boolean;
|
|
35
|
+
isPlaying: (sound: keyof T, spatial?: boolean) => boolean;
|
|
36
|
+
preloadAllSpatial: (emittersMap: Partial<Record<keyof T, BasePart[]>>) => void;
|
|
37
|
+
preloadSpatial: (name: keyof T, emitters: BasePart[]) => void;
|
|
38
|
+
destroy: (sound: keyof T, spatial?: boolean) => void;
|
|
34
39
|
};
|
|
@@ -20,27 +20,42 @@ local function createSoundRegistry(definitions)
|
|
|
20
20
|
*
|
|
21
21
|
* Loads a Sound
|
|
22
22
|
* @param name Define which Sound should be loaded
|
|
23
|
+
* @param spatial Array of BaseParts
|
|
23
24
|
|
|
24
25
|
]]
|
|
25
|
-
local function load(name)
|
|
26
|
-
if folder:FindFirstChild(name) then
|
|
27
|
-
return nil
|
|
28
|
-
end
|
|
26
|
+
local function load(name, spatial)
|
|
29
27
|
local config = definitions[name]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
if not spatial or not spatial.emitters then
|
|
29
|
+
if folder:FindFirstChild(name) then
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
local config = definitions[name]
|
|
33
|
+
local sound = Instance.new("Sound")
|
|
34
|
+
sound.Name = name
|
|
35
|
+
sound.SoundId = config.id
|
|
36
|
+
local _condition = config.volume
|
|
37
|
+
if _condition == nil then
|
|
38
|
+
_condition = 1
|
|
39
|
+
end
|
|
40
|
+
sound.Volume = _condition
|
|
41
|
+
local _condition_1 = config.loop
|
|
42
|
+
if _condition_1 == nil then
|
|
43
|
+
_condition_1 = false
|
|
44
|
+
end
|
|
45
|
+
sound.Looped = _condition_1
|
|
46
|
+
sound.Parent = folder
|
|
47
|
+
else
|
|
48
|
+
local emittersArray = spatial.emitters
|
|
49
|
+
local _exp = config.id
|
|
50
|
+
local _condition = config.volume
|
|
51
|
+
if _condition == nil then
|
|
52
|
+
_condition = 1
|
|
53
|
+
end
|
|
54
|
+
local handle = createSpatialHandle(_exp, emittersArray, _condition)
|
|
55
|
+
local _name = name
|
|
56
|
+
spatialHandles[_name] = handle
|
|
57
|
+
return handle
|
|
41
58
|
end
|
|
42
|
-
sound.Looped = _condition_1
|
|
43
|
-
sound.Parent = folder
|
|
44
59
|
end
|
|
45
60
|
--[[
|
|
46
61
|
*
|
|
@@ -83,6 +98,10 @@ local function createSoundRegistry(definitions)
|
|
|
83
98
|
local function stop(name, spatial)
|
|
84
99
|
if not spatial then
|
|
85
100
|
local sound = folder:FindFirstChild(name)
|
|
101
|
+
if not sound then
|
|
102
|
+
warn(`{name} not found! Tip: Preload the sound first before using it.`)
|
|
103
|
+
return nil
|
|
104
|
+
end
|
|
86
105
|
local _result = sound
|
|
87
106
|
if _result ~= nil then
|
|
88
107
|
_result:Stop()
|
|
@@ -109,6 +128,59 @@ local function createSoundRegistry(definitions)
|
|
|
109
128
|
load(name)
|
|
110
129
|
end
|
|
111
130
|
end
|
|
131
|
+
--[[
|
|
132
|
+
*
|
|
133
|
+
* Preloads all spatial Sounds
|
|
134
|
+
* @param emittersMap
|
|
135
|
+
|
|
136
|
+
]]
|
|
137
|
+
local function preloadAllSpatial(emittersMap)
|
|
138
|
+
for name, emitters in pairs(emittersMap) do
|
|
139
|
+
local emitterArray = emitters
|
|
140
|
+
if not emitterArray then
|
|
141
|
+
continue
|
|
142
|
+
end
|
|
143
|
+
local soundName = name
|
|
144
|
+
if spatialHandles[soundName] ~= nil then
|
|
145
|
+
continue
|
|
146
|
+
end
|
|
147
|
+
local config = definitions[soundName]
|
|
148
|
+
local _exp = config.id
|
|
149
|
+
local _condition = config.volume
|
|
150
|
+
if _condition == nil then
|
|
151
|
+
_condition = 1
|
|
152
|
+
end
|
|
153
|
+
local handle = createSpatialHandle(_exp, emitterArray, _condition)
|
|
154
|
+
spatialHandles[soundName] = handle
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
--[[
|
|
158
|
+
*
|
|
159
|
+
* Preloads a spatial sound
|
|
160
|
+
* @param name Sound Name
|
|
161
|
+
* @param emitters Emitters
|
|
162
|
+
|
|
163
|
+
]]
|
|
164
|
+
local function preloadSpatial(name, emitters)
|
|
165
|
+
local _name = name
|
|
166
|
+
if spatialHandles[_name] ~= nil then
|
|
167
|
+
return nil
|
|
168
|
+
end
|
|
169
|
+
local config = definitions[name]
|
|
170
|
+
if not config then
|
|
171
|
+
warn(`{name} is not defined in the registry.`)
|
|
172
|
+
return nil
|
|
173
|
+
end
|
|
174
|
+
local _exp = config.id
|
|
175
|
+
local _exp_1 = emitters
|
|
176
|
+
local _condition = config.volume
|
|
177
|
+
if _condition == nil then
|
|
178
|
+
_condition = 1
|
|
179
|
+
end
|
|
180
|
+
local handle = createSpatialHandle(_exp, _exp_1, _condition)
|
|
181
|
+
local _name_1 = name
|
|
182
|
+
spatialHandles[_name_1] = handle
|
|
183
|
+
end
|
|
112
184
|
--[[
|
|
113
185
|
*
|
|
114
186
|
* Smoothly fade in a sound
|
|
@@ -122,6 +194,10 @@ local function createSoundRegistry(definitions)
|
|
|
122
194
|
local config = definitions[soundName]
|
|
123
195
|
if not spatial or not spatial.emitters then
|
|
124
196
|
local sound = folder:FindFirstChild(soundName)
|
|
197
|
+
if not sound then
|
|
198
|
+
warn(`{soundName} not found! Tip: Preload the sound first before using it.`)
|
|
199
|
+
return nil
|
|
200
|
+
end
|
|
125
201
|
sound.Volume = 0
|
|
126
202
|
sound:Play()
|
|
127
203
|
local step = 0.05
|
|
@@ -168,6 +244,7 @@ local function createSoundRegistry(definitions)
|
|
|
168
244
|
if not spatial or not spatial.emitters then
|
|
169
245
|
local sound = folder:FindFirstChild(soundName)
|
|
170
246
|
if not sound then
|
|
247
|
+
warn(`{soundName} not found! Tip: Preload the sound first before using it.`)
|
|
171
248
|
return nil
|
|
172
249
|
end
|
|
173
250
|
local startVolume = sound.Volume
|
|
@@ -214,25 +291,43 @@ local function createSoundRegistry(definitions)
|
|
|
214
291
|
*
|
|
215
292
|
* Reset a Sound
|
|
216
293
|
* @param sound Sound Instance
|
|
294
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
217
295
|
|
|
218
296
|
]]
|
|
219
|
-
local function reset(sound)
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
297
|
+
local function reset(sound, spatial)
|
|
298
|
+
if not spatial then
|
|
299
|
+
local _sound = folder:FindFirstChild(sound)
|
|
300
|
+
if not _sound then
|
|
301
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
302
|
+
return nil
|
|
303
|
+
end
|
|
304
|
+
_sound.TimePosition = 0
|
|
305
|
+
end
|
|
306
|
+
local _sound_1 = sound
|
|
307
|
+
local _sound = spatialHandles[_sound_1]
|
|
308
|
+
local _result = _sound
|
|
309
|
+
if _result ~= nil then
|
|
310
|
+
_result:setTimePosition(0)
|
|
223
311
|
end
|
|
224
|
-
_sound.TimePosition = 0
|
|
225
312
|
end
|
|
226
313
|
--[[
|
|
227
314
|
*
|
|
228
315
|
* Reset every Sound
|
|
229
316
|
* @param sound Sound Instance
|
|
317
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
230
318
|
|
|
231
319
|
]]
|
|
232
|
-
local function resetAll(sound)
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
sound
|
|
320
|
+
local function resetAll(sound, spatial)
|
|
321
|
+
if not spatial then
|
|
322
|
+
for _, sound in folder:GetChildren() do
|
|
323
|
+
if sound:IsA("Sound") then
|
|
324
|
+
sound.TimePosition = 0
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
for _, instance in folder:GetChildren() do
|
|
329
|
+
if instance:IsA("AudioPlayer") then
|
|
330
|
+
instance.TimePosition = 0
|
|
236
331
|
end
|
|
237
332
|
end
|
|
238
333
|
end
|
|
@@ -241,24 +336,46 @@ local function createSoundRegistry(definitions)
|
|
|
241
336
|
* Set Time Position
|
|
242
337
|
* @param sound Sound Instance
|
|
243
338
|
* @param timePosition Time Position
|
|
339
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
244
340
|
|
|
245
341
|
]]
|
|
246
|
-
local function setTimePosition(sound, timePosition)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
342
|
+
local function setTimePosition(sound, timePosition, spatial)
|
|
343
|
+
if not spatial then
|
|
344
|
+
local _sound = folder:FindFirstChild(sound)
|
|
345
|
+
if not _sound then
|
|
346
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
347
|
+
return nil
|
|
348
|
+
end
|
|
349
|
+
_sound.TimePosition = timePosition
|
|
350
|
+
end
|
|
351
|
+
local _sound_1 = sound
|
|
352
|
+
local _sound = spatialHandles[_sound_1]
|
|
353
|
+
local _result = _sound
|
|
354
|
+
if _result ~= nil then
|
|
355
|
+
_result:setTimePosition(timePosition)
|
|
250
356
|
end
|
|
251
|
-
_sound.TimePosition = timePosition
|
|
252
357
|
end
|
|
253
358
|
--[[
|
|
254
359
|
*
|
|
255
360
|
* Stop every Sound
|
|
256
361
|
* @param reset Define whether every Sound should also be reset?
|
|
362
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
257
363
|
|
|
258
364
|
]]
|
|
259
|
-
local function stopAll(reset)
|
|
365
|
+
local function stopAll(reset, spatial)
|
|
366
|
+
if not spatial then
|
|
367
|
+
for _, instance in folder:GetChildren() do
|
|
368
|
+
if not instance:IsA("Sound") then
|
|
369
|
+
continue
|
|
370
|
+
end
|
|
371
|
+
instance:Stop()
|
|
372
|
+
if reset then
|
|
373
|
+
instance.TimePosition = 0
|
|
374
|
+
end
|
|
375
|
+
end
|
|
376
|
+
end
|
|
260
377
|
for _, instance in folder:GetChildren() do
|
|
261
|
-
if not instance:IsA("
|
|
378
|
+
if not instance:IsA("AudioPlayer") then
|
|
262
379
|
continue
|
|
263
380
|
end
|
|
264
381
|
instance:Stop()
|
|
@@ -279,7 +396,8 @@ local function createSoundRegistry(definitions)
|
|
|
279
396
|
local config = definitions[sound]
|
|
280
397
|
if not spatial or spatial.emitters then
|
|
281
398
|
local _sound = folder:FindFirstChild(sound)
|
|
282
|
-
if not
|
|
399
|
+
if not _sound then
|
|
400
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
283
401
|
return nil
|
|
284
402
|
end
|
|
285
403
|
_sound.Volume = volume
|
|
@@ -292,14 +410,25 @@ local function createSoundRegistry(definitions)
|
|
|
292
410
|
*
|
|
293
411
|
* Set the global Sound Volume
|
|
294
412
|
* @param volume Sound Volume
|
|
413
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
295
414
|
|
|
296
415
|
]]
|
|
297
|
-
local function setGlobalVolume(volume)
|
|
416
|
+
local function setGlobalVolume(volume, spatial)
|
|
417
|
+
if not spatial then
|
|
418
|
+
for _, instance in folder:GetChildren() do
|
|
419
|
+
if not instance:IsA("Sound") then
|
|
420
|
+
continue
|
|
421
|
+
end
|
|
422
|
+
if instance:IsA("Sound") then
|
|
423
|
+
instance.Volume = volume
|
|
424
|
+
end
|
|
425
|
+
end
|
|
426
|
+
end
|
|
298
427
|
for _, instance in folder:GetChildren() do
|
|
299
|
-
if not instance:IsA("
|
|
428
|
+
if not instance:IsA("AudioPlayer") then
|
|
300
429
|
continue
|
|
301
430
|
end
|
|
302
|
-
if instance:IsA("
|
|
431
|
+
if instance:IsA("AudioPlayer") then
|
|
303
432
|
instance.Volume = volume
|
|
304
433
|
end
|
|
305
434
|
end
|
|
@@ -309,12 +438,14 @@ local function createSoundRegistry(definitions)
|
|
|
309
438
|
* Does something on Sound end
|
|
310
439
|
* @param name Sound Name
|
|
311
440
|
* @param callback Callback
|
|
441
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
312
442
|
|
|
313
443
|
]]
|
|
314
444
|
local function onEnd(sound, callback, spatial)
|
|
315
445
|
if not spatial then
|
|
316
446
|
local _sound = folder:WaitForChild(sound)
|
|
317
447
|
if not _sound then
|
|
448
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
318
449
|
return nil
|
|
319
450
|
end
|
|
320
451
|
_sound.Ended:Connect(callback)
|
|
@@ -341,15 +472,59 @@ local function createSoundRegistry(definitions)
|
|
|
341
472
|
* Check whether a Sound is playing
|
|
342
473
|
* @param sound Sound Instance
|
|
343
474
|
* @returns Boolean
|
|
475
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
344
476
|
|
|
345
477
|
]]
|
|
346
|
-
local function isPlaying(sound)
|
|
347
|
-
|
|
348
|
-
|
|
478
|
+
local function isPlaying(sound, spatial)
|
|
479
|
+
if not spatial then
|
|
480
|
+
local _sound = folder:FindFirstChild(sound)
|
|
481
|
+
if not _sound then
|
|
482
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
483
|
+
end
|
|
484
|
+
if _sound.IsPlaying == true then
|
|
485
|
+
return true
|
|
486
|
+
else
|
|
487
|
+
return false
|
|
488
|
+
end
|
|
489
|
+
end
|
|
490
|
+
local _sound_1 = sound
|
|
491
|
+
local _sound = spatialHandles[_sound_1]
|
|
492
|
+
if not _sound then
|
|
493
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
494
|
+
end
|
|
495
|
+
local _result = _sound
|
|
496
|
+
if _result ~= nil then
|
|
497
|
+
_result = _result:playing()
|
|
498
|
+
end
|
|
499
|
+
if _result == true then
|
|
349
500
|
return true
|
|
350
|
-
else
|
|
351
|
-
return false
|
|
352
501
|
end
|
|
502
|
+
return false
|
|
503
|
+
end
|
|
504
|
+
--[[
|
|
505
|
+
*
|
|
506
|
+
* Delete a sound instance
|
|
507
|
+
* @param sound Sound Instance
|
|
508
|
+
* @param spatial Define whether this sound is a spatial sound or not
|
|
509
|
+
|
|
510
|
+
]]
|
|
511
|
+
local function destroy(sound, spatial)
|
|
512
|
+
if not spatial then
|
|
513
|
+
local instance = folder:FindFirstChild(sound)
|
|
514
|
+
if not instance then
|
|
515
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
516
|
+
return nil
|
|
517
|
+
end
|
|
518
|
+
instance:Destroy()
|
|
519
|
+
return nil
|
|
520
|
+
end
|
|
521
|
+
local _sound = sound
|
|
522
|
+
local handle = spatialHandles[_sound]
|
|
523
|
+
if not handle then
|
|
524
|
+
warn(`{sound} not found! Tip: Preload the sound first before using it.`)
|
|
525
|
+
return nil
|
|
526
|
+
end
|
|
527
|
+
handle:destroy()
|
|
353
528
|
end
|
|
354
529
|
return {
|
|
355
530
|
play = play,
|
|
@@ -367,6 +542,9 @@ local function createSoundRegistry(definitions)
|
|
|
367
542
|
resetAll = resetAll,
|
|
368
543
|
onEnd = onEnd,
|
|
369
544
|
isPlaying = isPlaying,
|
|
545
|
+
preloadAllSpatial = preloadAllSpatial,
|
|
546
|
+
preloadSpatial = preloadSpatial,
|
|
547
|
+
destroy = destroy,
|
|
370
548
|
}
|
|
371
549
|
end
|
|
372
550
|
return {
|
|
@@ -52,6 +52,12 @@ local function createSpatialHandle(assetId, emitters, volume)
|
|
|
52
52
|
played = function(self, callback)
|
|
53
53
|
player.Ended:Connect(callback)
|
|
54
54
|
end,
|
|
55
|
+
playing = function(self)
|
|
56
|
+
return player.IsPlaying
|
|
57
|
+
end,
|
|
58
|
+
setTimePosition = function(self, timeposition)
|
|
59
|
+
player.TimePosition = timeposition
|
|
60
|
+
end,
|
|
55
61
|
}
|
|
56
62
|
end
|
|
57
63
|
return {
|
package/out/core/options.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface SoundHandle {
|
|
|
14
14
|
fadeOut?(duration: number): void;
|
|
15
15
|
destroy(): void;
|
|
16
16
|
played(callback: () => void): void;
|
|
17
|
+
playing(): boolean;
|
|
18
|
+
setTimePosition(timeposition: number): void;
|
|
17
19
|
}
|
|
18
20
|
interface SoundDefinition {
|
|
19
21
|
id: string;
|
|
@@ -24,4 +26,10 @@ export interface CategoryOptions {
|
|
|
24
26
|
category: string;
|
|
25
27
|
sounds: Record<string, SoundDefinition>;
|
|
26
28
|
}
|
|
29
|
+
export interface AudioListenerHandle {
|
|
30
|
+
listener: AudioListener;
|
|
31
|
+
output: AudioDeviceOutput;
|
|
32
|
+
wire: Wire;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
27
35
|
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AudioListenerHandle } from "./core/options";
|
|
2
|
+
type ListenerParent = BasePart | Camera | Model;
|
|
3
|
+
/**
|
|
4
|
+
* Creates an Audio Listener
|
|
5
|
+
* @param parent BasePart | Camera | Model
|
|
6
|
+
*/
|
|
7
|
+
export declare function createAudioListener(parent: ListenerParent, name?: string): AudioListenerHandle | undefined;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
--[[
|
|
3
|
+
*
|
|
4
|
+
* Creates an Audio Listener
|
|
5
|
+
* @param parent BasePart | Camera | Model
|
|
6
|
+
|
|
7
|
+
]]
|
|
8
|
+
local function createAudioListener(parent, name)
|
|
9
|
+
if parent:FindFirstChild("Sound-Manager-AudioListener") then
|
|
10
|
+
warn("AudioListener already exists on this parent")
|
|
11
|
+
return nil
|
|
12
|
+
end
|
|
13
|
+
local listener = Instance.new("AudioListener")
|
|
14
|
+
local _condition = name
|
|
15
|
+
if _condition == nil then
|
|
16
|
+
_condition = "Sound-Manager-AudioListener"
|
|
17
|
+
end
|
|
18
|
+
listener.Name = _condition
|
|
19
|
+
listener.Parent = parent
|
|
20
|
+
local output = Instance.new("AudioDeviceOutput")
|
|
21
|
+
output.Name = "Sound-Manager-AudioOutput"
|
|
22
|
+
local wire = Instance.new("Wire")
|
|
23
|
+
wire.Name = "ListenerToOutput"
|
|
24
|
+
wire.SourceInstance = listener
|
|
25
|
+
wire.TargetInstance = output
|
|
26
|
+
output.Parent = wire
|
|
27
|
+
wire.Parent = listener
|
|
28
|
+
return {
|
|
29
|
+
listener = listener,
|
|
30
|
+
output = output,
|
|
31
|
+
wire = wire,
|
|
32
|
+
destroy = function(self)
|
|
33
|
+
listener:Destroy()
|
|
34
|
+
end,
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
return {
|
|
38
|
+
createAudioListener = createAudioListener,
|
|
39
|
+
}
|
package/out/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { currentPlayingSounds } from "./developer-tools/currentPlayingSounds";
|
|
|
3
3
|
import { soundProperties } from "./developer-tools/soundProperties";
|
|
4
4
|
export * from "./core/createSoundRegistry";
|
|
5
5
|
export * from "./core/createSoundCategoryRegistry";
|
|
6
|
+
export * from "./createAudioListener";
|
|
6
7
|
export declare namespace Developer_Tools {
|
|
7
8
|
const getTotalSoundCount: typeof TotalSoundCount;
|
|
8
9
|
const getCurrentPlayingSounds: typeof currentPlayingSounds;
|
package/out/init.luau
CHANGED
|
@@ -10,6 +10,9 @@ end
|
|
|
10
10
|
for _k, _v in TS.import(script, script, "core", "createSoundCategoryRegistry") or {} do
|
|
11
11
|
exports[_k] = _v
|
|
12
12
|
end
|
|
13
|
+
for _k, _v in TS.import(script, script, "createAudioListener") or {} do
|
|
14
|
+
exports[_k] = _v
|
|
15
|
+
end
|
|
13
16
|
local Developer_Tools = {}
|
|
14
17
|
do
|
|
15
18
|
local _container = Developer_Tools
|