giants-godot/singletons/Globals.gd

42 lines
1.0 KiB
GDScript3
Raw Normal View History

2021-09-22 18:04:03 +02:00
extends Node
var Bus = {
Master = "Master",
Ambiants = "Ambiants",
Sounds = "Sounds",
Music = "Music"
}
2021-09-23 21:19:11 +02:00
var target_position: Dictionary = create_empty_collision_dictionnary(Vector3.ZERO)
var process_3d_inputs: bool = true
func create_empty_collision_dictionnary(to: Vector3) -> Dictionary:
return {
"position": to,
"normal": null,
"collider_id": null,
"collider": null,
"shape": null,
"rid": null
}
2021-09-22 18:04:03 +02:00
func play_sound(sound: AudioStreamSample, bus: String, parent: Spatial = null):
if parent:
var stream = AudioStreamPlayer3D.new()
2021-10-01 15:50:16 +02:00
stream.global_transform = parent.global_transform
2021-09-22 18:04:03 +02:00
stream.stream = sound
2021-10-01 15:50:16 +02:00
stream.autoplay = true
stream.unit_size = 1000
stream.bus = bus
stream.unit_db = 5
parent.add_child(stream)
2021-09-22 18:04:03 +02:00
stream.connect("finished", stream, "queue_free")
else:
var stream = AudioStreamPlayer.new()
2021-10-01 15:50:16 +02:00
get_tree().root.add_child(stream)
2021-09-22 18:04:03 +02:00
stream.bus = bus
stream.stream = sound
2021-10-01 15:50:16 +02:00
stream.volume_db = linear2db(1)
2021-09-22 18:04:03 +02:00
stream.play()
stream.connect("finished", stream, "queue_free")