From 2a6384d87d0eb203d345c7b4db06e1a6446ec994 Mon Sep 17 00:00:00 2001 From: Juan Molteni Date: Fri, 10 Jan 2025 16:09:08 -0300 Subject: [PATCH 1/2] Add asset for shared asset bundles --- ...ssetBundleLoadingParametersSystemShould.cs | 53 ++++++++++++++++++- .../Scene/SceneAssetBundleManifest.cs | 8 ++- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs b/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs index ace0512779..423b41e6ef 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,54 @@ 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 firstCacheableHash = intent.CommonArguments.GetCacheableURL(); + world.Destroy(entity1); + + //Now, we simulate another scene, that may have a different version of asset bundle conversion + 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 secondCacheableHash = intent.CommonArguments.GetCacheableURL(); + + 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 firstCacheableHash = intent.CommonArguments.GetCacheableURL(); + world.Destroy(entity1); + + //Now, we simulate another scene, that may have a different version of asset bundle conversion + 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 secondCacheableHash = intent.CommonArguments.GetCacheableURL(); + + 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}")); } } From 342e7942b26a6269cd8b2c3c44295dda9853dd3a Mon Sep 17 00:00:00 2001 From: Juan Molteni Date: Fri, 10 Jan 2025 16:14:30 -0300 Subject: [PATCH 2/2] More detailed tests --- .../PrepareAssetBundleLoadingParametersSystemShould.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs b/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs index 423b41e6ef..09d2bfda02 100644 --- a/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs +++ b/Explorer/Assets/Scripts/ECS/StreamableLoading/AssetBundles/Tests/PrepareAssetBundleLoadingParametersSystemShould.cs @@ -131,18 +131,21 @@ public void ReturnDifferentCacheValuesForDifferentVersions() 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 may have a different version of asset bundle conversion + //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); } @@ -156,17 +159,20 @@ public void ReturnSameCacheValuesForScenes() 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 may have a different version of asset bundle conversion + //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); } }