Skip to content

Commit

Permalink
Revert "Merge pull request #650 from hadashiA/ku/fix-root-in-editor"
Browse files Browse the repository at this point in the history
This reverts commit 5bea225, reversing
changes made to d64a49a.
  • Loading branch information
hadashiA committed Mar 28, 2024
1 parent 93c0e55 commit e9b8a90
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions VContainer/Assets/VContainer/Runtime/Unity/VContainerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ public static void CreateAsset()
preloadedAssets.Add(newSettings);
UnityEditor.PlayerSettings.SetPreloadedAssets(preloadedAssets.ToArray());
}

public static void LoadInstanceFromPreloadAssets()
{
var preloadAsset = UnityEditor.PlayerSettings.GetPreloadedAssets().FirstOrDefault(x => x is VContainerSettings);
if (preloadAsset is VContainerSettings instance)
{
if (instance.RootLifetimeScope != null)
instance.RootLifetimeScope.DisposeCore();
instance.OnEnable();
}
}

[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void RuntimeInitialize()
{
// For editor, we need to load the Preload asset manually.
LoadInstanceFromPreloadAssets();
}
#endif

public LifetimeScope GetOrCreateRootLifetimeScopeInstance()
Expand Down

0 comments on commit e9b8a90

Please sign in to comment.