I started to learn Zenject + Unity. I learned the Zenject readme but I have no unity experience I need shared data between scenes and I want to have some code over the scene. I try to inject some GameData class in two scenes. My scenes have GameObjects with code where I use injections. The first scene has the installer and the first scene loads the second scene as an additive I make bind so:
public class MainInstaller : MonoInstaller
{
public override void InstallBindings()
{
Container.Bind<GameData>().AsSingle().NonLazy();
}
}
I guess that I will have one instance GameData
First scene:
private GameData _gameData;
[Inject]
public void Construct(GameData gameData)
{
_gameData = gameData;
SceneManager.LoadScene("Menu", LoadSceneMode.Additive);
}
private void Start()
{
_gameData.CurrentState = GameStates.Menu; // Makes some changes
}
Second scene
private GameData _gameData;
[Inject]
public void Construct(GameData gameData)
{
_gameData = gameData;
}
The injection works ok. But I don't see my changes in log. And I think that exist two instance of GameDate.