2024-02-27 23:21:44 +01:00

39 lines
970 B
GDScript

extends Node
@export var scene_path: String
@export var progress_bar: ProgressBar
@export var modulate: CanvasModulate
@export var fade_duration: float
@export var use_sub_threads: bool
var progress: Array
func _ready():
ResourceLoader.load_threaded_request(scene_path, "", use_sub_threads)
if OS.has_feature("editor"):
fade_duration /= 2
func _process(_delta: float):
var status := ResourceLoader.load_threaded_get_status(scene_path, progress)
progress_bar.value = progress[0] * 100
if status == ResourceLoader.THREAD_LOAD_LOADED:
on_loaded()
set_process(false)
func on_loaded():
add_scene()
fade_out()
func add_scene():
var scene := ResourceLoader.load_threaded_get(scene_path)
var node := scene.instantiate() as Node
get_tree().root.add_child(node)
func fade_out():
progress_bar.hide()
var tween = get_tree().create_tween()
tween.tween_property(modulate, "color", Color(1.0, 1.0, 1.0, 0), fade_duration)
tween.tween_callback(queue_free)