diff --git a/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs b/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs index ace0512779..09d2bfda02 100644 --- a/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs +++ b/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs @@ -65,7 +65,7 @@ public void LoadFromWebWithOldPath() Assert.That(intent.CommonArguments.URL, Is.EqualTo($"http://www.fakepath.com/{version}/abcd")); Assert.That(intent.cacheHash, Is.Not.Null); } - + [Test] public void LoadFromWebWithNewPath() { @@ -102,7 +102,7 @@ public void FailIfAbsentInManifestOldHash() Assert.That(result.Asset, Is.Null); Assert.That(result.Exception, Is.TypeOf().Or.InnerException.TypeOf()); } - + [Test] public void FailIfAbsentInManifestNewHash() { @@ -120,5 +120,60 @@ public void FailIfAbsentInManifestNewHash() Assert.That(result.Asset, Is.Null); Assert.That(result.Exception, Is.TypeOf().Or.InnerException.TypeOf()); } + + [Test] + public void ReturnDifferentCacheValuesForDifferentVersions() + { + //First, we simulate creation of a scene and the resolving of one asset budnle + string version = "v" + SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH; + sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024")); + var intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB); + Entity entity1 = world.Create(intent, new StreamableLoadingState()); + system.Update(0); + intent = world.Get(entity1); + string firstStandardURL = intent.CommonArguments.URL; + string firstCacheableHash = intent.CommonArguments.GetCacheableURL(); + world.Destroy(entity1); + + //Now, we simulate another scene, that has a different asset bundle version + version = "v" + (SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH + 1); + sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024")); + intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB); + Entity entity2 = world.Create(intent, new StreamableLoadingState()); + system.Update(0); + intent = world.Get(entity2); + string secondStandardURL = intent.CommonArguments.URL; + string secondCacheableHash = intent.CommonArguments.GetCacheableURL(); + + Assert.AreNotEqual(firstStandardURL, secondStandardURL); + Assert.AreNotEqual(firstCacheableHash, secondCacheableHash); + } + + [Test] + public void ReturnSameCacheValuesForScenes() + { + //First, we simulate creation of a scene and the resolving of one asset budnle + string version = "v" + SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH; + sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024")); + var intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB); + Entity entity1 = world.Create(intent, new StreamableLoadingState()); + system.Update(0); + intent = world.Get(entity1); + string firstStandardURL = intent.CommonArguments.URL; + string firstCacheableHash = intent.CommonArguments.GetCacheableURL(); + world.Destroy(entity1); + + //Now, we simulate another scene, that has a differente scene hash but same version + sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_2", "04_10_2024")); + intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB); + Entity entity2 = world.Create(intent, new StreamableLoadingState()); + system.Update(0); + intent = world.Get(entity2); + string secondStandardURL = intent.CommonArguments.URL; + string secondCacheableHash = intent.CommonArguments.GetCacheableURL(); + + Assert.AreNotEqual(firstStandardURL, secondStandardURL); + Assert.AreEqual(firstCacheableHash, secondCacheableHash); + } } } diff --git a/Explorer/Assets/Scripts/SceneRunner/Scene/SceneAssetBundleManifest.cs b/Explorer/Assets/Scripts/SceneRunner/Scene/SceneAssetBundleManifest.cs index fba8a10619..c416ad8f9f 100644 --- a/Explorer/Assets/Scripts/SceneRunner/Scene/SceneAssetBundleManifest.cs +++ b/Explorer/Assets/Scripts/SceneRunner/Scene/SceneAssetBundleManifest.cs @@ -81,11 +81,9 @@ public string GetVersion() => public string GetSceneID() => sceneID; - //Used for the OngoingRequests cache. We need to avoid version and sceneID in this URL to able to reuse assets. + //Used for the OngoingRequests cache. We need to avoid the sceneID in this URL to able to reuse assets. //The first loaded hash will be the one used for all the other requests - public URLAddress GetCacheableURL(string hash) - { - return assetBundlesBaseUrl.Append(new URLPath(hash)); - } + public URLAddress GetCacheableURL(string hash) => + assetBundlesBaseUrl.Append(new URLPath($"{version}/{hash}")); } }