SupaLidlGame/Utils/ScenePath.cs

33 lines
697 B
C#
Raw Permalink Normal View History

2023-12-29 17:45:36 -08:00
using Godot;
namespace SupaLidlGame.Utils;
[GlobalClass]
public partial class ScenePath : ResourcePath
{
private static Godot.Collections.Dictionary<string, PackedScene> _loaded;
static ScenePath()
{
_loaded = new();
}
public PackedScene Load(bool useCached = false)
{
if (useCached && _loaded.ContainsKey(Path))
{
return _loaded[Path];
}
// add scene to loaded to not have to reload scene when called again
var scene = base.Load<PackedScene>();
_loaded.Add(Path, scene);
return scene;
}
public T Instantiate<T>() where T : Node
{
return Load().Instantiate<T>();
}
}