supervisor-simulator/scripts/SceneTransit.cs
2024-12-06 17:14:41 +08:00

43 lines
1.1 KiB
C#

using Godot;
using System;
public partial class SceneTransit : CanvasLayer
{
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
Layer = -1;
Hide();
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public async void Transit(string nextScene, bool needLoadResources = true, string animation = "transit", float waitSecond = 0)
{
SetProcess(true);
GameManager.NextScene = nextScene;
var ap = GetNode<AnimationPlayer>("AnimationPlayer");
Layer = 9999;
Show();
ap.Play(animation);
await ToSignal(ap, AnimationMixer.SignalName.AnimationFinished);
if (waitSecond > 0) {
await ToSignal(GetTree().CreateTimer(waitSecond), SceneTreeTimer.SignalName.Timeout);
}
if (needLoadResources) {
GetTree().ChangeSceneToFile("res://scenes/loader.tscn");
} else {
GetTree().ChangeSceneToFile(nextScene);
}
ap.PlayBackwards(animation);
await ToSignal(ap, AnimationMixer.SignalName.AnimationFinished);
Layer = -1;
Hide();
SetProcess(false);
}
}