WIP new SceneTransition system
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.SceneManagement;
|
||||
public partial class SceneTransitionThreaded : Node2D
|
||||
{
|
||||
public static SceneTransitionThreaded Instance { get; private set; }
|
||||
|
||||
// set to true if don't wanna use it
|
||||
public bool userCodeLoadCompleted = true;
|
||||
|
||||
private ThreadedLoadingStateEn threadedLoadingState = ThreadedLoadingStateEn._none;
|
||||
public enum ThreadedLoadingStateEn
|
||||
{
|
||||
_none,
|
||||
_fading_in,
|
||||
_loading,
|
||||
_loading_user_code
|
||||
}
|
||||
|
||||
[Export] private AnimationPlayer animationPlayer;
|
||||
private string scenePathThreaded = "";
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
CheckLoadThreaded();
|
||||
}
|
||||
|
||||
private void CheckLoadThreaded()
|
||||
{
|
||||
if (scenePathThreaded == "")
|
||||
{ return; }
|
||||
|
||||
if (threadedLoadingState == ThreadedLoadingStateEn._loading && ResourceLoader.LoadThreadedGetStatus(scenePathThreaded) == ResourceLoader.ThreadLoadStatus.Loaded)
|
||||
{
|
||||
OnResourceLoadThreadedComplete();
|
||||
}
|
||||
else if (threadedLoadingState == ThreadedLoadingStateEn._loading_user_code && userCodeLoadCompleted)
|
||||
{
|
||||
OnResourceLoadThreadedCompleteUserCode();
|
||||
}
|
||||
}
|
||||
|
||||
public async void ChangeSceneToFile(string scenePath)
|
||||
{
|
||||
animationPlayer.Play("fadeIn");
|
||||
//yield(animationPlayer, "animation_finished");
|
||||
await ToSignal(animationPlayer, "animation_finished");
|
||||
GetTree().ChangeSceneToFile(scenePath);
|
||||
animationPlayer.Play("fadeOut");
|
||||
}
|
||||
|
||||
public void OnFadeInCompletedThreaded()
|
||||
{
|
||||
if (scenePathThreaded == "")
|
||||
{ return; }
|
||||
|
||||
ResourceLoader.LoadThreadedRequest(scenePathThreaded);
|
||||
threadedLoadingState = ThreadedLoadingStateEn._loading;
|
||||
}
|
||||
|
||||
// https://docs.godotengine.org/en/stable/tutorials/io/background_loading.html
|
||||
public void ChangeSceneToFileThreaded(string scenePath)
|
||||
{
|
||||
scenePathThreaded = scenePath;
|
||||
animationPlayer.Play("fadeIn");
|
||||
threadedLoadingState = ThreadedLoadingStateEn._fading_in;
|
||||
}
|
||||
|
||||
private void OnResourceLoadThreadedComplete()
|
||||
{
|
||||
PackedScene loadedScene = (PackedScene)ResourceLoader.LoadThreadedGet(scenePathThreaded);
|
||||
//Node sceneInstance = loadedScene.Instantiate();
|
||||
GetTree().ChangeSceneToPacked(loadedScene);
|
||||
threadedLoadingState = ThreadedLoadingStateEn._loading_user_code;
|
||||
}
|
||||
|
||||
private void OnResourceLoadThreadedCompleteUserCode()
|
||||
{
|
||||
animationPlayer.Play("fadeOut");
|
||||
scenePathThreaded = "";
|
||||
threadedLoadingState = ThreadedLoadingStateEn._none;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bo2jik2jtuqlw
|
||||
Reference in New Issue
Block a user