39 lines
970 B
GDScript3
Raw Permalink Normal View History

2024-02-14 10:38:32 +00:00
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)
2024-02-23 21:29:20 +00:00
if OS.has_feature("editor"):
fade_duration /= 2
2024-02-27 22:21:44 +00:00
func _process(_delta: float):
2024-02-14 10:38:32 +00:00
var status := ResourceLoader.load_threaded_get_status(scene_path, progress)
progress_bar.value = progress[0] * 100
if status == ResourceLoader.THREAD_LOAD_LOADED:
2024-02-23 21:29:20 +00:00
on_loaded()
set_process(false)
func on_loaded():
add_scene()
fade_out()
2024-02-14 10:38:32 +00:00
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)
2024-02-25 22:01:17 +00:00
tween.tween_callback(queue_free)