Skip to content

Commit

Permalink
Changes scene injection to awake
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavopsantos committed Sep 20, 2022
1 parent 6158371 commit 76df4e3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Assets/Reflex/Scripts/Core/SceneContext.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
using UnityEngine;
using Reflex.Scripts.Events;

namespace Reflex.Scripts.Core
{
[DefaultExecutionOrder(-10000)]
public class SceneContext : AContext
{
private void Awake()
{
UnityStaticEvents.OnSceneEarlyAwake.Invoke(gameObject.scene);
}

public override void InstallBindings(Container container)
{
base.InstallBindings(container);
Expand Down
3 changes: 3 additions & 0 deletions Assets/Reflex/Scripts/Events.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Assets/Reflex/Scripts/Events/UnityStaticEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using UnityEngine.SceneManagement;

namespace Reflex.Scripts.Events
{
public static class UnityStaticEvents
{
public static Action<Scene> OnSceneEarlyAwake;
}
}
3 changes: 3 additions & 0 deletions Assets/Reflex/Scripts/Events/UnityStaticEvents.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Assets/Reflex/Scripts/Injectors/UnityInjector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UnityEngine;
using Reflex.Scripts.Core;
using Reflex.Scripts.Events;
using Reflex.Scripts.Utilities;
using UnityEngine.SceneManagement;

namespace Reflex.Injectors
{
Expand All @@ -11,7 +11,8 @@ internal static class UnityInjector
private static void AfterAssembliesLoaded()
{
var projectContainer = CreateProjectContainer();
SceneManager.sceneLoaded += (scene, mode) => SceneInjector.Inject(scene, projectContainer);
//SceneManager.sceneLoaded += (scene, mode) => SceneInjector.Inject(scene, projectContainer);
UnityStaticEvents.OnSceneEarlyAwake += scene => SceneInjector.Inject(scene, projectContainer);
}

private static Container CreateProjectContainer()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ A single prefab named `ProjectContext` that should live inside a `Resources` fol
### Scene Context
A single root gameobject per scene that should contain a `SceneContext` component attached
> Non-Obligatory to have
> Non-Obligatory to have, but scenes without it wont be injected
## Bindings

Expand Down

0 comments on commit 76df4e3

Please sign in to comment.