Files
godot-host-test/addons/GodotDI/SceneInstantiator.cs
T
2026-07-18 12:09:43 +02:00

30 lines
982 B
C#

using System;
using System.Linq;
using Godot;
using Microsoft.Extensions.Logging;
using OwofGames.GodotLume;
namespace GodotHostTest.GodotDI;
internal class SceneInstantiator(IProvider provider) : ISceneInstantiator
{
/// <inheritdoc />
public Node Instantiate(PackedScene packedScene, Delegate? onScopeCreated = null)
{
var node = packedScene.Instantiate();
var scope = node.GetChildren().OfType<ServiceSource>().SingleOrDefault();
if (scope == null)
provider.Get<ILogger<SceneInstantiator>>().LogDebug(
"Instantiated the scene {PackedSceneName} through ISceneInstantiator.Instantiate, but no scope found.",
packedScene.GetName());
else
scope.ResolveInjectedNodes(provider, onScopeCreated);
return node;
}
public T Instantiate<T>(PackedScene packedScene, Delegate? onScopeCreated = null) where T : Node
{
throw new NotImplementedException();
}
}