Class: Engine::Components::AudioSource
Instance Attribute Summary
#game_object
Instance Method Summary
collapse
#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #start, #ui_renderer?
allowed_class?, get_class, included, register_class, #uuid
Instance Method Details
#add_delay_tap(time_ms:, volume:) ⇒ Object
53
54
55
|
# File 'lib/engine/components/audio_source.rb', line 53
def add_delay_tap(time_ms:, volume:)
@source.add_delay_tap(time_ms: time_ms, volume: volume)
end
|
#awake ⇒ Object
7
8
9
10
11
|
# File 'lib/engine/components/audio_source.rb', line 7
def awake
@radius ||= 1000
@clip = NativeAudio::Clip.new(@clip_path)
@source = NativeAudio::AudioSource.new(@clip)
end
|
#duration ⇒ Object
41
42
43
|
# File 'lib/engine/components/audio_source.rb', line 41
def duration
@clip.duration
end
|
#looping=(looping) ⇒ Object
37
38
39
|
# File 'lib/engine/components/audio_source.rb', line 37
def looping=(looping)
@source.set_looping(looping)
end
|
#pause ⇒ Object
21
22
23
|
# File 'lib/engine/components/audio_source.rb', line 21
def pause
@source.pause
end
|
#pitch=(pitch) ⇒ Object
33
34
35
|
# File 'lib/engine/components/audio_source.rb', line 33
def pitch=(pitch)
@source.set_pitch(pitch)
end
|
#play ⇒ Object
13
14
15
|
# File 'lib/engine/components/audio_source.rb', line 13
def play
@source.play
end
|
#resume ⇒ Object
25
26
27
|
# File 'lib/engine/components/audio_source.rb', line 25
def resume
@source.resume
end
|
#set_reverb(enabled: true, room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0) ⇒ Object
45
46
47
48
49
50
51
|
# File 'lib/engine/components/audio_source.rb', line 45
def set_reverb(enabled: true, room_size: 0.5, damping: 0.3, wet: 0.3, dry: 1.0)
if enabled
@source.set_reverb(room_size: room_size, damping: damping, wet: wet, dry: dry)
else
@source.enable_reverb(false)
end
end
|
#stop ⇒ Object
17
18
19
|
# File 'lib/engine/components/audio_source.rb', line 17
def stop
@source.stop
end
|
#update(delta_time) ⇒ Object
57
58
59
60
61
62
63
64
65
|
# File 'lib/engine/components/audio_source.rb', line 57
def update(delta_time)
camera = Engine::Camera.instance
local_pos = camera.game_object.world_to_local_coordinate(game_object.pos)
angle = Math.atan2(local_pos[0], -local_pos[2]) * 180 / Math::PI
angle = (angle + 360) % 360
distance = (local_pos.magnitude * 255 / @radius).clamp(0, 255)
@source.set_pos(angle, distance)
end
|
#volume=(volume) ⇒ Object
29
30
31
|
# File 'lib/engine/components/audio_source.rb', line 29
def volume=(volume)
@source.set_volume(volume)
end
|