parent
e8c24e18be
commit
16251db248
@ -1,10 +1,95 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bopv10dqm1knc"]
|
||||
[gd_scene load_steps=7 format=3 uid="uid://bopv10dqm1knc"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://c6wnoif01ltld" path="res://scenes/Babushka_scene_startMenu.tscn" id="1_15ton"]
|
||||
[ext_resource type="Script" uid="uid://bo2jik2jtuqlw" path="res://scripts/CSharp/Common/SceneManagement/SceneTransitionThreaded.cs" id="1_d3jfo"]
|
||||
|
||||
[node name="BabushkaSceneBootstrap" type="Node2D"]
|
||||
[sub_resource type="Animation" id="Animation_t7str"]
|
||||
length = 0.001
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SceneFadeAnimation/CanvasLayer/ColorRect:color")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 0,
|
||||
"values": [Color(1, 1, 1, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_e43hv"]
|
||||
resource_name = "fadeIn"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SceneFadeAnimation/CanvasLayer/ColorRect:color")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.966667),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(0, 0, 0, 0), Color(0, 0, 0, 1)]
|
||||
}
|
||||
tracks/1/type = "method"
|
||||
tracks/1/imported = false
|
||||
tracks/1/enabled = true
|
||||
tracks/1/path = NodePath(".")
|
||||
tracks/1/interp = 1
|
||||
tracks/1/loop_wrap = true
|
||||
tracks/1/keys = {
|
||||
"times": PackedFloat32Array(0.966667),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"values": [{
|
||||
"args": [],
|
||||
"method": &"OnFadeInCompletedThreaded"
|
||||
}]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_d3jfo"]
|
||||
resource_name = "fadeOut"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("SceneFadeAnimation/CanvasLayer/ColorRect:color")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0, 0.966667),
|
||||
"transitions": PackedFloat32Array(1, 1),
|
||||
"update": 0,
|
||||
"values": [Color(0, 0, 0, 1), Color(0, 0, 0, 0)]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_5o782"]
|
||||
_data = {
|
||||
&"RESET": SubResource("Animation_t7str"),
|
||||
&"fadeIn": SubResource("Animation_e43hv"),
|
||||
&"fadeOut": SubResource("Animation_d3jfo")
|
||||
}
|
||||
|
||||
[node name="BabushkaSceneBootstrap" type="Node2D" node_paths=PackedStringArray("animationPlayer")]
|
||||
script = ExtResource("1_d3jfo")
|
||||
animationPlayer = NodePath("SceneFadeAnimation")
|
||||
|
||||
[node name="BabushkaSceneStartMenu" parent="." node_paths=PackedStringArray("_sceneInstanceParent") instance=ExtResource("1_15ton")]
|
||||
_sceneInstanceParent = NodePath("../SceneParent")
|
||||
|
||||
[node name="SceneParent" type="Node" parent="."]
|
||||
|
||||
[node name="SceneFadeAnimation" type="AnimationPlayer" parent="."]
|
||||
libraries = {
|
||||
&"": SubResource("AnimationLibrary_5o782")
|
||||
}
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="SceneFadeAnimation"]
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="SceneFadeAnimation/CanvasLayer"]
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 2
|
||||
color = Color(1, 1, 1, 0)
|
||||
|
||||
@ -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
|
||||
Loading…
Reference in new issue