Files
godot-host-test/addons/AetherBind/SceneInstantiatorExtensions.cs
redglow e7dbb9cabb .
2026-07-21 20:49:24 +02:00

25 lines
1.1 KiB
C#

using System;
using Godot;
using OwofGames.GodotLume;
namespace GodotHostTest.AetherBind;
public static class SceneInstantiatorExtensions
{
/// <summary>
/// Instantiate a packed scene, just like <see cref="PackedScene.Instantiate{T}" />, but also looks for a scope between
/// the top level children and triggers the dependency injection mechanism when found.
/// </summary>
/// <param name="sceneInstantiator">The scene instantiator to use.</param>
/// <param name="packedScene">The packed scene to instantiate.</param>
/// <param name="onScopeCreated">
/// An optional callback invoked once the scope has been created, but before instantiating the
/// scene, with the provider as argument.
/// </param>
/// <returns>The created node, with its dependencies satisfied.</returns>
public static T Instantiate<T>(this ISceneInstantiator sceneInstantiator, PackedScene packedScene,
Action<IProvider>? onScopeCreated = null) where T : Node
{
return (T)sceneInstantiator.Instantiate(packedScene, onScopeCreated);
}
}