Skip to content

Commit

Permalink
Merge pull request #126 from hadashiA/ku/support-domain-reload
Browse files Browse the repository at this point in the history
  • Loading branch information
hadashiA authored Feb 13, 2021
2 parents 240146d + e549b6d commit f5d6f82
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ partial class LifetimeScope
static readonly List<(LifetimeScope, VContainerParentTypeReferenceNotFound)> WaitingList =
new List<(LifetimeScope, VContainerParentTypeReferenceNotFound)>();

#if UNITY_2019_3_OR_NEWER
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
#else
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
#endif
static void SubscribeSceneEvents()
{
SceneManager.sceneLoaded -= AwakeWaitingChildren;
Expand Down
20 changes: 16 additions & 4 deletions VContainer/Assets/VContainer/Runtime/Unity/LifetimeScope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ LifetimeScope GetRuntimeParent()
if (parentReference.Object != null)
return parentReference.Object;

// Find in scene via type
if (parentReference.Type != null && parentReference.Type != GetType())
{
var found = Find(parentReference.Type);
Expand All @@ -268,15 +269,26 @@ LifetimeScope GetRuntimeParent()
$"{name} could not found parent reference of type : {parentReference.Type}");
}

// Find root from settings
if (VContainerSettings.Instance is VContainerSettings settings)
{
if (settings.RootLifetimeScope != null)
var rootLifetimeScope = settings.RootLifetimeScope;
#if UNITY_EDITOR
var disableDomainReloading = UnityEditor.EditorSettings.enterPlayModeOptionsEnabled &&
(UnityEditor.EditorSettings.enterPlayModeOptions &
UnityEditor.EnterPlayModeOptions.DisableDomainReload) > 0;
if (rootLifetimeScope == null && disableDomainReloading)
{
if (settings.RootLifetimeScope.Container == null)
UnityEngine.Debug.LogError("VContainerSettings.RootLifetimeScope is missing. Please try to re-compile C# scripts just once.");
}
#endif
if (rootLifetimeScope != null)
{
if (rootLifetimeScope.Container == null)
{
settings.RootLifetimeScope.Build();
rootLifetimeScope.Build();
}
return settings.RootLifetimeScope;
return rootLifetimeScope;
}
}
return null;
Expand Down
11 changes: 4 additions & 7 deletions VContainer/Assets/VContainer/Runtime/Unity/PlayerLoopHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using UnityEngine;
using System.Threading;
#if UNITY_2019_3_OR_NEWER
using UnityEngine.LowLevel;
using UnityEngine.PlayerLoop;
Expand Down Expand Up @@ -42,16 +42,13 @@ enum PlayerLoopTiming
static class PlayerLoopHelper
{
static readonly PlayerLoopRunner[] Runners = new PlayerLoopRunner[10];
static bool initialized;
static long initialized;

// [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void Initialize()
{
lock (Runners)
{
if (initialized) return;
initialized = true;
}
if (Interlocked.CompareExchange(ref initialized, 1, 0) != 0)
return;

for (var i = 0; i < Runners.Length; i++)
{
Expand Down

1 comment on commit f5d6f82

@vercel
Copy link

@vercel vercel bot commented on f5d6f82 Feb 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.