Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scene loading #44

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Runtime/Context/AutoContextLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Construct(IContext context)
public async Task AfterInject()
{
// If this context is loaded from child scene context, do not load child scene contexts.
if (Context.IsReverseLoaded) return;
if (!enabled || Context.IsReverseLoaded) return;

foreach (var sceneContext in sceneContexts)
await Context.SceneContextLoader.LoadAsync(sceneContext, active: true);
Expand Down
4 changes: 2 additions & 2 deletions Runtime/Context/ParentSceneContextRequirement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public async Task<IContext> ResolveParentContext(SceneContext current)
#if UNITY_EDITOR
using var scope = new ParentContextLoadingScope(gameObject.scene);

handle = await UnifiedSceneLoader.LoadAsync(Scene, destroyCancellationToken);
var scene = await handle.GetScene();
handle = UnifiedSceneLoader.LoadAsync(Scene);
var scene = await handle.GetScene(destroyCancellationToken);

var sceneContext = scene.FindFirstObjectByType<SceneContext>();
if (!sceneContext)
Expand Down
22 changes: 17 additions & 5 deletions Runtime/Context/SceneContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,26 @@ var gameObjectContexts
= GetComponentsUnderContext<GameObjectContext>()
.Where(x => x.enabled);

await ContextInternal.RawContainer.GenerateResolvers();
try
{
await ContextInternal.RawContainer.GenerateResolvers();

await Task.WhenAll(injectableComponents.Select(x
=> ContextInternal.RawContainer.InjectIntoAsync(x).AsTask()));
await Task.WhenAll(injectableComponents.Select(x
=> ContextInternal.RawContainer.InjectIntoAsync(x).AsTask()));

while (InjectionProcessing)
await TaskHelper.NextFrame(destroyCancellationToken);
while (InjectionProcessing)
await TaskHelper.NextFrame(destroyCancellationToken);

}
catch (Exception _)
{
if (ParentContext is not null && !ParentContext.Loaded)
{
Debug.LogWarning("Parent context is not loaded. Shutdown SceneContext.");
await Shutdown();
return;
}
}
using (new ContextSpaceScope(this))
{
foreach (var gameObjectContext in gameObjectContexts)
Expand Down
1 change: 1 addition & 0 deletions Runtime/Context/SceneContextLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SceneContextLoader : MonoBehaviour, IAsyncDisposable
private IContext Context { get; set; }
private List<IContext> ChildSceneContexts { get; } = new();
public IReadOnlyList<IContext> ReadonlyChildSceneContexts => ChildSceneContexts;
public float Progression => SceneLoader.Progression;
private TaskQueue TaskQueue { get; } = new();
private bool Disposed { get; set; }

Expand Down