ssannandeji / Zenject-2019

Dependency Injection Framework for Unity3D

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ZenjectSceneLoader, editor and asset bundles

reflexing opened this issue · comments

Hello.

I tried to use data injection across scenes and encountered the following issue: we use asset bundles and they are simulated in Editor, so SceneManager.LoadSceneAsync in ZenjectSceneLoader.LoadSceneAsync doesn't work.

Added this to ZenjectSceneLoader to circumvent the issue:

#if UNITY_EDITOR
        public AsyncOperation LoadSceneAsyncEditor(
            string scenePath,
            LoadSceneMode loadMode = LoadSceneMode.Single,
            Action<DiContainer> extraBindings = null,
            LoadSceneRelationship containerMode = LoadSceneRelationship.None,
            Action<DiContainer> extraBindingsLate = null)
        {
            PrepareForLoadScene(loadMode, extraBindings, extraBindingsLate, containerMode);

            if (loadMode == LoadSceneMode.Single)
                return UnityEditor.EditorApplication.LoadLevelAsyncInPlayMode(scenePath);
            else
                return UnityEditor.EditorApplication.LoadLevelAdditiveAsyncInPlayMode(scenePath);
        }
#endif

I wonder if this is a correct approach. If it is, maybe you can add it to Zenject, I think many teams use AssetBundleManager. Thanks.