challenge-editor/autoload/scene_manager/script/scene_manager.gd
2024-09-19 17:56:05 +08:00

61 lines
1.9 KiB
GDScript

extends CanvasLayer
@onready var animation_player: AnimationPlayer = $AnimationPlayer
@onready var h_box_container: HBoxContainer = $ColorRect/HBoxContainer
@onready var color_rect: ColorRect = $ColorRect
@onready var percent: Label = $ColorRect/HBoxContainer/percent
@onready var breath: AnimationPlayer = $breath
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
set_process(false)
pass # Replace with function body.
var load_path:String=""
func change_scene_to(path:String):
color_rect.show()
animation_player.play("open")
await animation_player.animation_finished
h_box_container.show()
percent.text="0"
breath.play("breath")
await get_tree().create_timer(0.2).timeout
percent.text="20"
await get_tree().create_timer(0.2).timeout
load_path=path
ResourceLoader.load_threaded_request(path,"PackedScene")
set_process(true)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if load_path=="":
return
var progress=[]
var status:ResourceLoader.ThreadLoadStatus=ResourceLoader.load_threaded_get_status(load_path,progress)
match status:
ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
percent.text="100"
load_end()
ResourceLoader.THREAD_LOAD_IN_PROGRESS:
percent.text=str(int(progress[0]*100))
ResourceLoader.THREAD_LOAD_FAILED:
percent.text="100"
var scene=ResourceLoader.load_threaded_get(load_path)
get_tree().change_scene_to_packed(scene)
load_end()
ResourceLoader.THREAD_LOAD_LOADED:
percent.text="100"
var scene=ResourceLoader.load_threaded_get(load_path)
get_tree().change_scene_to_packed(scene)
load_end()
pass
pass
func load_end():
load_path=""
set_process(false)
await get_tree().create_timer(0.2).timeout
h_box_container.hide()
breath.stop()
animation_player.play_backwards("open")
await animation_player.animation_finished
color_rect.hide()