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"); 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); } }