Skip to content

Commit

Permalink
Merge pull request #44 from mewlist/fix-scene-loading
Browse files Browse the repository at this point in the history
Fix scene loading
  • Loading branch information
mewlist authored Feb 22, 2024
2 parents 6752e87 + c65319f commit 02b057a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
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

0 comments on commit 02b057a

Please sign in to comment.