Last active
September 21, 2021 17:56
-
-
Save schetle/64369e9c25c87b738b1de7eac4391b4a to your computer and use it in GitHub Desktop.
localPhysicsMode support for Addressables.LoadSceneAsync (Unity Addressables 1.18.15)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git ./Runtime/Addressables.cs ./Runtime/Addressables.cs | |
index 0ffdc89..18c49d1 100644 | |
--- ./Runtime/Addressables.cs | |
+++ ./Runtime/Addressables.cs | |
@@ -1203,14 +1203,16 @@ namespace UnityEngine.AddressableAssets | |
/// </summary> | |
/// <param name="key">The key of the location of the scene to load.</param> | |
/// <param name="loadMode">Scene load mode.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode.</param> | |
/// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> | |
/// <param name="priority">Async operation priority for scene loading.</param> | |
/// <returns>The operation handle for the request.</returns> | |
//[Obsolete("We have added Async to the name of all asycn methods (UnityUpgradable) -> LoadSceneAsync(*)", true)] | |
[Obsolete] | |
- public static AsyncOperationHandle<SceneInstance> LoadScene(object key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ public static AsyncOperationHandle<SceneInstance> LoadScene(object key, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
- return LoadSceneAsync(key, loadMode, activateOnLoad, priority); | |
+ return LoadSceneAsync(key, loadMode, localPhysicsMode, activateOnLoad, priority); | |
} | |
/// <summary> | |
@@ -1218,14 +1220,16 @@ namespace UnityEngine.AddressableAssets | |
/// </summary> | |
/// <param name="location">The location of the scene to load.</param> | |
/// <param name="loadMode">Scene load mode.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode.</param> | |
/// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> | |
/// <param name="priority">Async operation priority for scene loading.</param> | |
/// <returns>The operation handle for the request.</returns> | |
//[Obsolete("We have added Async to the name of all asycn methods (UnityUpgradable) -> LoadSceneAsync(*)", true)] | |
[Obsolete] | |
- public static AsyncOperationHandle<SceneInstance> LoadScene(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ public static AsyncOperationHandle<SceneInstance> LoadScene(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
- return LoadSceneAsync(location, loadMode, activateOnLoad, priority); | |
+ return LoadSceneAsync(location, loadMode, localPhysicsMode, activateOnLoad, priority); | |
} | |
/// <summary> | |
@@ -1234,12 +1238,13 @@ namespace UnityEngine.AddressableAssets | |
/// </summary> | |
/// <param name="key">The key of the location of the scene to load.</param> | |
/// <param name="loadMode">Scene load mode.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode.</param> | |
/// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> | |
/// <param name="priority">Async operation priority for scene loading.</param> | |
/// <returns>The operation handle for the request.</returns> | |
- public static AsyncOperationHandle<SceneInstance> LoadSceneAsync(object key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ public static AsyncOperationHandle<SceneInstance> LoadSceneAsync(object key, LoadSceneMode loadMode = LoadSceneMode.Single, LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
- return m_Addressables.LoadSceneAsync(key, loadMode, activateOnLoad, priority); | |
+ return m_Addressables.LoadSceneAsync(key, loadMode, localPhysicsMode, activateOnLoad, priority); | |
} | |
/// <summary> | |
@@ -1248,12 +1253,14 @@ namespace UnityEngine.AddressableAssets | |
/// </summary> | |
/// <param name="location">The location of the scene to load.</param> | |
/// <param name="loadMode">Scene load mode.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode.</param> | |
/// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> | |
/// <param name="priority">Async operation priority for scene loading.</param> | |
/// <returns>The operation handle for the request.</returns> | |
- public static AsyncOperationHandle<SceneInstance> LoadSceneAsync(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ public static AsyncOperationHandle<SceneInstance> LoadSceneAsync(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
- return m_Addressables.LoadSceneAsync(location, loadMode, activateOnLoad, priority); | |
+ return m_Addressables.LoadSceneAsync(location, loadMode, localPhysicsMode, activateOnLoad, priority); | |
} | |
/// <summary> | |
diff --git ./Runtime/AddressablesImpl.cs ./Runtime/AddressablesImpl.cs | |
index e77aaa7..00107ac 100644 | |
--- ./Runtime/AddressablesImpl.cs | |
+++ ./Runtime/AddressablesImpl.cs | |
@@ -1140,26 +1140,29 @@ namespace UnityEngine.AddressableAssets | |
return true; | |
} | |
- internal AsyncOperationHandle<SceneInstance> LoadSceneWithChain(AsyncOperationHandle dep, object key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ internal AsyncOperationHandle<SceneInstance> LoadSceneWithChain(AsyncOperationHandle dep, object key, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
- return TrackHandle(ResourceManager.CreateChainOperation(dep, op => LoadSceneAsync(key, loadMode, activateOnLoad, priority, false))); | |
+ return TrackHandle(ResourceManager.CreateChainOperation(dep, op => LoadSceneAsync(key, loadMode, localPhysicsMode, activateOnLoad, priority, false))); | |
} | |
- public AsyncOperationHandle<SceneInstance> LoadSceneAsync(object key, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100, bool trackHandle = true) | |
+ public AsyncOperationHandle<SceneInstance> LoadSceneAsync(object key, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100, bool trackHandle = true) | |
{ | |
if (ShouldChainRequest) | |
- return LoadSceneWithChain(ChainOperation, key, loadMode, activateOnLoad, priority); | |
+ return LoadSceneWithChain(ChainOperation, key, loadMode, localPhysicsMode, activateOnLoad, priority); | |
IList<IResourceLocation> locations; | |
if (!GetResourceLocations(key, typeof(SceneInstance), out locations)) | |
return ResourceManager.CreateCompletedOperationWithException<SceneInstance>(default(SceneInstance), new InvalidKeyException(key, typeof(SceneInstance))); | |
- return LoadSceneAsync(locations[0], loadMode, activateOnLoad, priority, trackHandle); | |
+ return LoadSceneAsync(locations[0], loadMode, localPhysicsMode, activateOnLoad, priority, trackHandle); | |
} | |
- public AsyncOperationHandle<SceneInstance> LoadSceneAsync(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100, bool trackHandle = true) | |
+ public AsyncOperationHandle<SceneInstance> LoadSceneAsync(IResourceLocation location, LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100, bool trackHandle = true) | |
{ | |
- var handle = ResourceManager.ProvideScene(SceneProvider, location, loadMode, activateOnLoad, priority); | |
+ var handle = ResourceManager.ProvideScene(SceneProvider, location, loadMode, localPhysicsMode, activateOnLoad, priority); | |
if (trackHandle) | |
return TrackHandle(handle); | |
diff --git ./Runtime/AssetReference.cs ./Runtime/AssetReference.cs | |
index 8fbd0d1..5920a3b 100644 | |
--- ./Runtime/AssetReference.cs | |
+++ ./Runtime/AssetReference.cs | |
@@ -512,17 +512,19 @@ namespace UnityEngine.AddressableAssets | |
/// See the [Loading Addressable Assets](xref:addressables-api-load-asset-async) documentation for more details. | |
/// </summary> | |
/// <param name="loadMode">Scene load mode.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode.</param> | |
/// <param name="activateOnLoad">If false, the scene will load but not activate (for background loading). The SceneInstance returned has an Activate() method that can be called to do this at a later point.</param> | |
/// <param name="priority">Async operation priority for scene loading.</param> | |
/// <returns>The operation handle for the request if there is not a valid cached operation, otherwise return default operation</returns> | |
- public virtual AsyncOperationHandle<SceneInstance> LoadSceneAsync(LoadSceneMode loadMode = LoadSceneMode.Single, bool activateOnLoad = true, int priority = 100) | |
+ public virtual AsyncOperationHandle<SceneInstance> LoadSceneAsync(LoadSceneMode loadMode = LoadSceneMode.Single, | |
+ LocalPhysicsMode localPhysicsMode = LocalPhysicsMode.None, bool activateOnLoad = true, int priority = 100) | |
{ | |
AsyncOperationHandle<SceneInstance> result = default(AsyncOperationHandle<SceneInstance>); | |
if (m_Operation.IsValid()) | |
Debug.LogError("Attempting to load AssetReference Scene that has already been loaded. Handle is exposed through getter OperationHandle"); | |
else | |
{ | |
- result = Addressables.LoadSceneAsync(RuntimeKey, loadMode, activateOnLoad, priority); | |
+ result = Addressables.LoadSceneAsync(RuntimeKey, loadMode, localPhysicsMode, activateOnLoad, priority); | |
m_Operation = result; | |
} | |
return result; | |
diff --git ./Runtime/ResourceManager/ResourceManager.cs ./Runtime/ResourceManager/ResourceManager.cs | |
index 3072a3f..69f0136 100644 | |
--- ./Runtime/ResourceManager/ResourceManager.cs | |
+++ ./Runtime/ResourceManager/ResourceManager.cs | |
@@ -948,15 +948,17 @@ namespace UnityEngine.ResourceManagement | |
/// <param name="sceneProvider">The scene provider instance.</param> | |
/// <param name="location">The location of the scene.</param> | |
/// <param name="loadMode">The load mode for the scene.</param> | |
+ /// <param name="localPhysicsMode">The local physics mode for the scene.</param> | |
/// <param name="activateOnLoad">If false, the scene will be loaded in the background and not activated when complete.</param> | |
/// <param name="priority">The priority for the load operation.</param> | |
/// <returns>Async operation handle that will complete when the scene is loaded. If activateOnLoad is false, then Activate() will need to be called on the SceneInstance returned.</returns> | |
- public AsyncOperationHandle<SceneInstance> ProvideScene(ISceneProvider sceneProvider, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority) | |
+ public AsyncOperationHandle<SceneInstance> ProvideScene(ISceneProvider sceneProvider, IResourceLocation location, LoadSceneMode loadMode, | |
+ LocalPhysicsMode localPhysicsMode, bool activateOnLoad, int priority) | |
{ | |
if (sceneProvider == null) | |
throw new NullReferenceException("sceneProvider is null"); | |
- return sceneProvider.ProvideScene(this, location, loadMode, activateOnLoad, priority); | |
+ return sceneProvider.ProvideScene(this, location, loadMode, localPhysicsMode, activateOnLoad, priority); | |
} | |
/// <summary> | |
diff --git ./Runtime/ResourceManager/ResourceProviders/ISceneProvider.cs ./Runtime/ResourceManager/ResourceProviders/ISceneProvider.cs | |
index 28aa235..154d2c3 100644 | |
--- ./Runtime/ResourceManager/ResourceProviders/ISceneProvider.cs | |
+++ ./Runtime/ResourceManager/ResourceProviders/ISceneProvider.cs | |
@@ -65,10 +65,11 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
/// <param name="resourceManager">The resource manager to use for loading dependencies.</param> | |
/// <param name="location">The location of the scene.</param> | |
/// <param name="loadMode">Load mode for the scene.</param> | |
+ /// <param name="localPhysicsMode">Local physics mode for the scene.</param> | |
/// <param name="activateOnLoad">If true, the scene is activated as soon as it finished loading. Otherwise it needs to be activated via the returned SceneInstance object.</param> | |
/// <param name="priority">The loading priority for the load.</param> | |
/// <returns>An operation handle for the loading of the scene. The scene is wrapped in a SceneInstance object to support delayed activation.</returns> | |
- AsyncOperationHandle<SceneInstance> ProvideScene(ResourceManager resourceManager, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority); | |
+ AsyncOperationHandle<SceneInstance> ProvideScene(ResourceManager resourceManager, IResourceLocation location, LoadSceneMode loadMode, LocalPhysicsMode localPhysicsMode, bool activateOnLoad, int priority); | |
/// <summary> | |
/// Release a scene. | |
/// </summary> | |
diff --git ./Runtime/ResourceManager/ResourceProviders/SceneProvider.cs ./Runtime/ResourceManager/ResourceProviders/SceneProvider.cs | |
index dfc77f8..2d79bc0 100644 | |
--- ./Runtime/ResourceManager/ResourceProviders/SceneProvider.cs | |
+++ ./Runtime/ResourceManager/ResourceProviders/SceneProvider.cs | |
@@ -21,6 +21,7 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
SceneInstance m_Inst; | |
IResourceLocation m_Location; | |
LoadSceneMode m_LoadMode; | |
+ LocalPhysicsMode m_LocalPhysicsMode; | |
int m_Priority; | |
private AsyncOperationHandle<IList<AsyncOperationHandle>> m_DepOp; | |
ResourceManager m_ResourceManager; | |
@@ -34,7 +35,7 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
return m_DepOp.IsValid() ? m_DepOp.InternalGetDownloadStatus(visited) : new DownloadStatus() { IsDone = IsDone }; | |
} | |
- public void Init(IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority, AsyncOperationHandle<IList<AsyncOperationHandle>> depOp) | |
+ public void Init(IResourceLocation location, LoadSceneMode loadMode, LocalPhysicsMode localPhysicsMode, bool activateOnLoad, int priority, AsyncOperationHandle<IList<AsyncOperationHandle>> depOp) | |
{ | |
m_DepOp = depOp; | |
if (m_DepOp.IsValid()) | |
@@ -42,6 +43,7 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
m_Location = location; | |
m_LoadMode = loadMode; | |
+ m_LocalPhysicsMode = localPhysicsMode; | |
m_ActivateOnLoad = activateOnLoad; | |
m_Priority = priority; | |
} | |
@@ -86,29 +88,29 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
loadingFromBundle = true; | |
} | |
} | |
- m_Inst = InternalLoadScene(m_Location, loadingFromBundle, m_LoadMode, m_ActivateOnLoad, m_Priority); | |
+ m_Inst = InternalLoadScene(m_Location, loadingFromBundle, m_LoadMode, m_LocalPhysicsMode, m_ActivateOnLoad, m_Priority); | |
((IUpdateReceiver)this).Update(0.0f); | |
if(!IsDone) | |
m_ResourceManager.AddUpdateReceiver(this); | |
HasExecuted = true; | |
} | |
- internal SceneInstance InternalLoadScene(IResourceLocation location, bool loadingFromBundle, LoadSceneMode loadMode, bool activateOnLoad, int priority) | |
+ internal SceneInstance InternalLoadScene(IResourceLocation location, bool loadingFromBundle, LoadSceneMode loadMode, LocalPhysicsMode localPhysicsMode, bool activateOnLoad, int priority) | |
{ | |
var internalId = m_ResourceManager.TransformInternalId(location); | |
- var op = InternalLoad(internalId, loadingFromBundle, loadMode); | |
+ var op = InternalLoad(internalId, loadingFromBundle, loadMode, localPhysicsMode); | |
op.allowSceneActivation = activateOnLoad; | |
op.priority = priority; | |
return new SceneInstance() { m_Operation = op, Scene = SceneManager.GetSceneAt(SceneManager.sceneCount - 1) }; | |
} | |
- AsyncOperation InternalLoad(string path, bool loadingFromBundle, LoadSceneMode mode) | |
+ AsyncOperation InternalLoad(string path, bool loadingFromBundle, LoadSceneMode mode, LocalPhysicsMode localPhysicsMode) | |
{ | |
#if !UNITY_EDITOR | |
- return SceneManager.LoadSceneAsync(path, new LoadSceneParameters() { loadSceneMode = mode }); | |
+ return SceneManager.LoadSceneAsync(path, new LoadSceneParameters() { loadSceneMode = mode, localPhysicsMode = localPhysicsMode }); | |
#else | |
if (loadingFromBundle) | |
- return SceneManager.LoadSceneAsync(path, new LoadSceneParameters() { loadSceneMode = mode }); | |
+ return SceneManager.LoadSceneAsync(path, new LoadSceneParameters() { loadSceneMode = mode, localPhysicsMode = localPhysicsMode }); | |
else | |
{ | |
if (!path.ToLower().StartsWith("assets/") && !path.ToLower().StartsWith("packages/")) | |
@@ -116,7 +118,7 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
if (path.LastIndexOf(".unity") == -1) | |
path += ".unity"; | |
- return UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(path, new LoadSceneParameters() { loadSceneMode = mode }); | |
+ return UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(path, new LoadSceneParameters() { loadSceneMode = mode, localPhysicsMode = localPhysicsMode }); | |
} | |
#endif | |
} | |
@@ -217,14 +219,14 @@ namespace UnityEngine.ResourceManagement.ResourceProviders | |
} | |
/// <inheritdoc/> | |
- public AsyncOperationHandle<SceneInstance> ProvideScene(ResourceManager resourceManager, IResourceLocation location, LoadSceneMode loadMode, bool activateOnLoad, int priority) | |
+ public AsyncOperationHandle<SceneInstance> ProvideScene(ResourceManager resourceManager, IResourceLocation location, LoadSceneMode loadMode, LocalPhysicsMode localPhysicsMode, bool activateOnLoad, int priority) | |
{ | |
AsyncOperationHandle<IList<AsyncOperationHandle>> depOp = default(AsyncOperationHandle<IList<AsyncOperationHandle>>); | |
if (location.HasDependencies) | |
depOp = resourceManager.ProvideResourceGroupCached(location.Dependencies, location.DependencyHashCode, typeof(IAssetBundleResource), null); | |
SceneOp op = new SceneOp(resourceManager); | |
- op.Init(location, loadMode, activateOnLoad, priority, depOp); | |
+ op.Init(location, loadMode, localPhysicsMode, activateOnLoad, priority, depOp); | |
var handle = resourceManager.StartOperation<SceneInstance>(op, depOp); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment