giants-godot/singletons/Globals.gd
2021-10-01 15:50:16 +02:00

42 lines
1.0 KiB
GDScript

extends Node
var Bus = {
Master = "Master",
Ambiants = "Ambiants",
Sounds = "Sounds",
Music = "Music"
}
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
}
func play_sound(sound: AudioStreamSample, bus: String, parent: Spatial = null):
if parent:
var stream = AudioStreamPlayer3D.new()
stream.global_transform = parent.global_transform
stream.stream = sound
stream.autoplay = true
stream.unit_size = 1000
stream.bus = bus
stream.unit_db = 5
parent.add_child(stream)
stream.connect("finished", stream, "queue_free")
else:
var stream = AudioStreamPlayer.new()
get_tree().root.add_child(stream)
stream.bus = bus
stream.stream = sound
stream.volume_db = linear2db(1)
stream.play()
stream.connect("finished", stream, "queue_free")